-1
在node.js/express/socket.io
應用程序中,如何手動調用express
來加載/呈現主頁,而不用說app.use(blah)
。換句話說,如果我想要通過手動加載index.html
而不是自動加載。手動呼叫
var express = require('express'),
app = express(),
...
//app.use magically loads index.html when the browser hits 8080
app.use(express.static(path.join(__dirname, '../client/www'))); //index.html is in www
var port = process.env.PORT || 8080; //select your port or let it pull from your .env file
//===============PORT=================
http.listen(port, function() {
console.log('listening on: ' + port);
}
其中index.html位於www
?這不起作用:
app.get('/', function(req, res){
res.sendfile('index.html', { root: __dirname + "/relative_path_of_file" });
});
這也不:
app.get('/', function(req, res){
res.render('/home/idf/Documents/js/react-trader/client/www/index.html', {user: req.user});
});