neverendingqs / netlify-express

Express.js hosted on Netlify
https://netlify-express.netlify.app/
Apache License 2.0
321 stars 341 forks source link

Only root route returns #6

Open roowilliams opened 5 years ago

roowilliams commented 5 years ago

https://netlify-express.netlify.com/ renders, https://netlify-express.netlify.com/another returns a 404.

I've been trying to build a simple app using this as a boilerplate, and none of my defined routes work apart from /. Any ideas?

neverendingqs commented 5 years ago

The root route is a somewhat hacky way to demonstrate the Express server works. You can reach the /another route by hitting it directly via https://netlify-express.netlify.com/.netlify/functions/server/another.

baires commented 5 years ago

@neverendingqs Is there any way to route /.netlify/functions/server/another to /another? or maybe to map it to a subdomain?

neverendingqs commented 5 years ago

I haven't had a chance to try it yet, but a rewrite rule might do the trick: https://www.netlify.com/docs/redirects/#rewrites-and-proxying

umanghome commented 5 years ago

Add this to netlify.toml

[[redirects]]
  from = "/*"
  to = "/.netlify/functions/server/:splat"
  status = 200
victorocna commented 4 years ago

Sadly, the redirect rules do not work. The curios thing is that they do work when I run netlify dev from the command line.

I've been trying to add a view engine for this express app, but I get a error similar to Error: Failed to lookup view "index" in views directory "/var/task/views". Any help please?

paulshryock commented 4 years ago

I agree this would be a lot more useful with redirects in place.

AndreasLagoni commented 3 years ago

I have the same issue but only locally. When i deploy to Netlify the other routes is working fine but locally they don't work.

router.get('/', (req, res) => {
  res.status(200).send("/")
});

router.get('/another', (req, res) => res.json({
  route: req.originalUrl
}));

app.use(bodyParser.json());
app.use('/.netlify/functions/server', router); // path must route to lambda
app.use('/', (req, res) => res.sendFile(path.join(__dirname, '../index.html')));

module.exports = app;
module.exports.handler = serverless(app);

/another will not work locally. Locally it will always go to root path. Any idea why? :)