Express Server With MongoDB 404 Accessing API
I have an Express server to host a react build file/folder and create api routes for get and post requests. I have setup a mongodb service and a repo (the express + build) and have connected the mongohost, pass, etc variables in the repo service.
However, I recieve 404 errors when trying to access the API in my app/build
Request URL:
https://from-below-studio-react-production.up.railway.app/api/login
Request Method:
POST
Status Code:
404 Not Found
Here is my connection file for the db
if (process.env.NODE_ENV === 'production') {
const mongoUser = process.env.MONGOUSER;
const mongoPassword = process.env.MONGOPASSWORD;
const mongoHost = process.env.MONGOHOST;
const mongoPort = process.env.MONGOPORT;
connectionString =
mongodb://${mongoUser}:${mongoPassword}@${mongoHost}:${mongoPort}
;
} else {
connectionString = 'mongodb://127.0.0.1:27017/from-below';
}
in my server.js where db is the connection file above:
db.once("open", () => {
httpServer.listen(PORT, () => {});
});
I copied an express mongo template to poke around and saw the api looks like this
Request URL:
https://mongo-express-production-a41d.up.railway.app/db/admin/
Request Method:
GET
Status Code:
304 Not Modified
What am I missing here?9 Replies
Project ID:
d93c4f4d-7dd2-456b-beaf-d27e6094a5bb
project id: d93c4f4d-7dd2-456b-beaf-d27e6094a5bb
can you provide your github repo?
GitHub
GitHub - Humberto-Zayas/from-below-studio-react
Contribute to Humberto-Zayas/from-below-studio-react development by creating an account on GitHub.
do you have two railway services in your project? one for the server and one for the client?
yes I have a mongodb and the git repo
well one mongodb and then I have the gitrepo which consists of an express server that serves some build files from a react app
I see that your backed is setup to serve the frontend, that is far from ideal, let's work through the steps to deploy this as an isolated monorepo
ok ty
you need two railway services, one for the client and one for the server, show me a screenshot of your project when that's done please