I've written a website in node.js and express. Now I configured lighttpd to use the node.js server with an subdirectory:
$HTTP["url"] =~ "^/app/" {
proxy.server = ( "" => ( (
"host" => "127.0.0.1",
"port" => 3000
) )
)
}
When I open http://localhost/app/
I get error 404 because I wrote something like this:
app.get('/', function (req, res){
res.render('index');
});
Is there a better way as modifying these lines like:
var relPath = '/app';
app.get(relPath + '/', function (req, res){
res.render('index');
});
?
relative() Method. The path. relative() method is used to find the relative path from a given path to another path based on the current working directory. If both the given paths are the same, it would resolve to a zero-length string.
It gives the current working directory of the Node. js process. __dirname: It is a local variable that returns the directory name of the current module. It returns the folder path of the current JavaScript file.
Express is a node js web application framework that provides broad features for building web and mobile applications. It is used to build a single page, multipage, and hybrid web application. It's a layer built on the top of the Node js that helps manage servers and routes.
As Ryan commented the solution is:
app.use('/app', app.router);
If you use e.g. express.static or express.favicon you have to tell app.use the path also:
app.use('/app', express.favicon(__dirname + '/public/images/favicon.ico'));
app.use('/app', express.static(__dirname + '/public'));
Remember to write '/app' before each internal link you set in your html.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With