a year 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
a year ago
Yes. d9e723dd-08af-409b-bf3b-2afbf84f0169
a year ago
Ok. Give me a minute because is private
a year ago
Yes
a year ago
What do you mean by testing? that would be the proper way to setup this kind of stack in Railway.
a year ago
I got confused, I thought you were asking about both frontend services. My english is not good
a year ago
Ah ok, yes, in the repo is only client.
a year ago
Sorry, yes, both frontend and Server are in the repository.
a year ago
Okay, and do you have a Railway project with both those services deployed? can you attach a screenshot of your Railway project please?
a year ago
Okey
Attachments
a year ago
Do you have the respective root directories set for the frontend and server services?
a year 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.
a year 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 build
in your Client's package.jsonIf you have any build or start commands set in your Client's Railway service settings, remove them.
a year ago
Ok. What repo? I don't see any link? Sorry
a year ago
Oh, I'm so sorry, the formatting of this form removed it from my comment. Updated.
a year ago
Now I see it. Thank you very much, I'll test it out and come back with updates
a year 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
a year ago
Maybe when it was downloaded, the extension was added. Now I will try again. Thanks
a year ago
WORKS GREAT!! π₯³ ThankU!!
a year ago
Ohhh, some routes doesn't work π«
a year 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.
a year ago
a year ago
Okay, thankU again!
a year ago
This might be as simple as setting base
to /
https://github.com/maxivalli/TiendasLocales/blob/TESTDEPLOY/Client/vite.config.js#L106
a year ago
Okey, I will try now
a year ago
You are the BOSS!! Now works
a year ago
π«Άπ»