Open roowilliams opened 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.
@neverendingqs Is there any way to route /.netlify/functions/server/another
to /another
? or maybe to map it to a subdomain?
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
Add this to netlify.toml
[[redirects]]
from = "/*"
to = "/.netlify/functions/server/:splat"
status = 200
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?
I agree this would be a lot more useful with redirects in place.
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? :)
https://netlify-express.netlify.com/
renders,https://netlify-express.netlify.com/another
returns a404
.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?