PERN Application with React Router -- WebSocket connection to 'xxx' failed:
I read a previous thread where it was suggested to use serve when running the client in production mode, but this solution does not work with React Router in my understanding.
Could it be as simple as changing my client start script? This is my first time hosting an application.
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
24 Replies
Project ID:
3bf7a56e-38fc-403a-92fa-0dcccfe80e97
3bf7a56e-38fc-403a-92fa-0dcccfe80e97
react router is client side right?
Yessir
server scripts:
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "nodemon index.js &",
"run dev": "nodemon index.js"
},
does react router require the server to redirect all requests to index.html?
I'm all ears
What's bad here
^
I don't think so?
index.html is in the client side and only contains some metadata and the root for injecting the react build
is your react app a spa app?
Bear with me I'm honestly quite stupid. I don't know if it counts as a SPA if it's technically rendering all of this content in the single html page "index.html" or if the inclusion of a router that builds URLs dynamically means its not a SPA
is there only one .html file named index.html in the build folder?
Yes
then its a single page app
Solution
Awesome π thanks again for the support.
let me know if you need any clarification
I'll give it a shot now
Oh, serve should be installed in client folder yeah? or does it matter
vs global
it looks like you have modified your scripts quite a bit, please go back to the default start scripts before you start that guide
should be installed as a project dependency
and that is what
npm i serve
will doNice, I'm online, no web socket errors, client and server are happy. thanks.
sanity check, can you show me your current scripts?
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "node index.js",
"run dev": "nodemon index.js"
},
"scripts": {
"dev": "react-scripts start",
"start": "serve build -s -n -L -p $PORT",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
why did you send two
First was server. Irrelevant
ahhh
okay all looks good to me!