Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only root route returns #6

Open
roowilliams opened this issue Feb 17, 2019 · 7 comments
Open

Only root route returns #6

roowilliams opened this issue Feb 17, 2019 · 7 comments

Comments

@roowilliams
Copy link

roowilliams commented Feb 17, 2019

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
Copy link
Owner

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
Copy link

baires commented Mar 14, 2019

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

@neverendingqs
Copy link
Owner

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
Copy link

Add this to netlify.toml

[[redirects]]
  from = "/*"
  to = "/.netlify/functions/server/:splat"
  status = 200

@victorocna
Copy link

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
Copy link

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

@AndreasLagoni
Copy link

AndreasLagoni commented May 12, 2021

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? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants