I’m working on a single-page application that doesn’t require any redirects. I’ve tried running it locally using netlify dev
and testing it with Postman, but I’m still encountering issues. The favicon isn’t loading, but I suspect the problem is more significant than that as I also have 404. I believe there’s a configuration error somewhere in my setup, but I’ve tried various combinations without success. Any guidance would be greatly appreciated.
netlify.toml
[build]
functions = "functions"
publish = "public"
[functions.app]
external_node_modules = ["express", "ejs", "serve-favicon"]
node_bundler = "esbuild"
included_files = ["views/**", "public/**"]
[[redirects]]
from = "/(.*)"
status = 200
to = "/.netlify/functions/app/:splat"
packadge.json
{
"name": "port",
"version": "1.0.0",
"description": "webpage",
"main": "app.js",
"scripts": {
"start": "node app.js",
"build": "netlify-lambda build ."
},
"author": "",
"license": "ISC",
"dependencies": {
"@netlify/functions": "^2.8.2",
"ejs": "^3.1.10",
"express": "^4.21.1",
"netlify-cli": "^17.37.1",
"netlify-lambda": "^2.0.16",
"serve-favicon": "^2.5.0",
"serverless-http": "^3.2.0"
}
}
app.js
const express = require('express');
const serverless = require('serverless-http');
const app = express();
const path = require("path");
const favicon = require('serve-favicon');
// Set EJS as the template engine
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));
// Serve static files (CSS, JS, etc.)
app.use(express.static(path.join(__dirname, "public")));
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')))
// Define route to render your main page
app.get("/", (req, res) => {
res.render("index");
});
// Catch-all route to handle all other paths (404 page)
app.get('*', (req, res) => {
res.status(404).send('Page Not Found');
});
// Define a path for serverless functions
app.use('/.netlify/functions/api', (req, res) => {
res.send('Serverless Function is working!');
});
// Export serverless handler
module.exports.handler = serverless(app);