Firstly I'd like to thank you and everyone part of this community after years of lurking around I finally asked my first question, hopefully soon I'll be able to provide answers too! :)
So to summarize the problem, I'm getting 404's on my routes (except homepage) configuration is ubuntu20/nginx/nodejs/express app hosted on Hostinger VPS, I've tried hitting it up with their support, but they are clueless and referred me here, not such a bad idea I thought!
What is weird:
- It was working perfectly fine (lol)
- On localhost works
- Believing it was one of the recent updates, after a while of debugging I thought, "screw that, just roll back to the last backup" which was working perfectly fine!
However, to my surprise the working backup, isn't working anymore, I'm 100% sure it was working, since I continued working for days, which couldn't have been done without working routes.
The nginx error log is empty, the access log is showing [05/Dec/2021:17:02:30 +0000] "POST /api/search HTTP/1.1" 404 194 "https://domain.io/" - this is the proper route.
I'm already typing more than most of the questions here, please guide me and I will provide anything possible.
Also I heard express is "dead" should I just switch to something else in hopes it will 'solve' this?
THANK YOU!
Updates:
- tried sudo apt-get update, removed node_modules, reinstalled all
- tried to rename the homepage route from app.get("/" to app.get("/home" and tried to access domain.io/home and it didn't work! On localhost it works fine
- reboot server, restart everything, as I said even restored working backup, this issue is beyond me...
Update 2:
I tried a different file, and installed Fastify and tried a default config of
// Require the framework and instantiate it const fastify = require('fastify')({ logger: true })
// Declare a route fastify.get('/', async (request, reply) => { return { hello: 'world' } })// Declare a route fastify.get('/test', async (request, reply) => { return { hello: 'test' } })
// Run the server! const start = async () => { try { await fastify.listen(3000) } catch (err) { fastify.log.error(err) process.exit(1) } } start() The homepage route works, but /test doesn't (even though it works on local) I'm 99.99% sure this is a hosting issue, what do you think?
UPDATE 3: FINALLY GOT IT, someone please explain how this is possible, inside my nginx config, this line was causing it, after removing everything works.
try_files $uri $uri/ =404;
Can anyone, please explain to me, how my server worked fine for a week with this 'error' inside the config? Keep in mind I restarted nginx dozens of times, this 'line' worked! Sorry for venting, but how is this possible?