My functions work fine when I use netlify dev, but when I deploy my site I get the following error
7:52:09 AM: f2637c76 ERROR Error: Failed to lookup view "index.html" in views directory "/public/views"
at Function.y.render (/var/task/src/server.js:247:4328)
at ServerResponse.E.render (/var/task/src/server.js:302:7991)
at /var/task/src/server.js:159:3815
at s.handle_request (/var/task/src/server.js:125:782)
at s (/var/task/src/server.js:118:879)
at p.dispatch (/var/task/src/server.js:118:901)
at s.handle_request (/var/task/src/server.js:125:782)
at /var/task/src/server.js:111:2533
at Function.v.process_params (/var/task/src/server.js:111:3436)
at g (/var/task/src/server.js:111:2476)
In local it works if I use relative paths, i.e.
app.use(express.static(path.join(__dirname, â./publicâ)));
app.set(âviewsâ, â./public/viewsâ)
Thanks for sharing so much context in your first post. I am sorry to hear you are having trouble with your deployed functions. Can you share your functions name so we can check our logs?
Additionally, have you read through our Docs about Functions?
In your package json you specify "main": "[functions/server.js.
Iâm pretty sure with netlify and using serverless-http is to use Express as a callable function. So it can serve as an endpoint to your website. Netlify deploys your code to the edge as static files so it wouldnât be able to run the server.
Hopefully I am on the right track! I also noticed that you mentioned it âworks fine when you use netlify devâ. I am curious about this, it looks like in your package json, you start script is "start": "nodemon server-local.js" and then that script points to
require('./express/server');
app.listen(3000, () => console.log('Local app listening on port 3000!'));
Which would lead me to believe that you yourself would at that point be running the server, thus making it work, rather than it being called as an endpoint via a netlify function.
I hope this helps, I tried to explain my though process when glancing over the code!