2 years ago
I have a project built with Express, Node.js, and Vite. If I set up routing with HashRouter, I have no issues. But if I use BrowserRouter, I get 404 errors when I refresh on a route other than the root. I understand it's a server-side routing issue, but I don't know how to solve it. Can anyone help me?
40 Replies
2 years ago
Yes. d9e723dd-08af-409b-bf3b-2afbf84f0169
2 years ago
Ok. Give me a minute because is private
2 years ago
Yes
2 years ago
What do you mean by testing? that would be the proper way to setup this kind of stack in Railway.
2 years ago
I got confused, I thought you were asking about both frontend services. My english is not good
2 years ago
Ah ok, yes, in the repo is only client.
2 years ago
Sorry, yes, both frontend and Server are in the repository.
2 years ago
Okay, and do you have a Railway project with both those services deployed? can you attach a screenshot of your Railway project please?
2 years ago
Do you have the respective root directories set for the frontend and server services?
2 years ago
Yes, at the moment everything is working because I have routing configured with HashRouter, but if I change it to BrowserRouter, it doesn't work.
2 years ago
Great, just needed to make sure you have the Railway side of things setup properly.
https://github.com/brody192/vite-react-template
Copy the nixpacks.toml and Caddyfile from this repo into your Client folder.
Delete your railway.json file in the Client's folder
Change the build script to just
vite buildin your Client's package.jsonIf you have any build or start commands set in your Client's Railway service settings, remove them.
2 years ago
Ok. What repo? I don't see any link? Sorry
2 years ago
Oh, I'm so sorry, the formatting of this form removed it from my comment. Updated.
2 years ago
Now I see it. Thank you very much, I'll test it out and come back with updates
2 years ago
I have this error during build
20 [stage-0 14/15] RUN caddy fmt --overwrite Caddyfile
20 0.429 Error: reading input file: open Caddyfile: no such file or directory
20 ERROR: process "/bin/bash -ol pipefail -c caddy fmt --overwrite Caddyfile" did not complete successfully: exit code: 1
[stage-0 14/15] RUN caddy fmt --overwrite Caddyfile:
0.429 Error: reading input file: open Caddyfile: no such file or directory
Dockerfile:34
32 | # fmt phase
33 | COPY . /app/.
34 | >>> RUN caddy fmt --overwrite Caddyfile
35 |
36 |
ERROR: failed to solve: process "/bin/bash -ol pipefail -c caddy fmt --overwrite Caddyfile" did not complete successfully: exit code: 1
Error: Docker build failed
2 years ago
Maybe when it was downloaded, the extension was added. Now I will try again. Thanks
2 years ago
WORKS GREAT!! 🥳 ThankU!!
2 years ago
Ohhh, some routes doesn't work 😫
2 years ago
Yes, I'm doing it. I see this error in the console of the browser: Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
2 years ago
2 years ago
Okay, thankU again!
2 years ago
This might be as simple as setting base to /
https://github.com/maxivalli/TiendasLocales/blob/TESTDEPLOY/Client/vite.config.js#L106
2 years ago
Okey, I will try now
2 years ago
You are the BOSS!! Now works
2 years ago
🫶🏻