“Cannot GET /” with Connect on Node.js

后端 未结 10 1234
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 00:40

I\'m trying to start serving some static web pages using connect like this:

var connect = require(\"connect\");
var nowjs = require(\"now\");
va         


        
10条回答
  •  渐次进展
    2020-12-01 01:22

    You typically want to render templates like this:

    app.get('/', function(req, res){
      res.render('index.ejs');
    });
    

    However you can also deliver static content - to do so use:

    app.use(express.static(__dirname + '/public'));
    

    Now everything in the /public directory of your project will be delivered as static content at the root of your site e.g. if you place default.htm in the public folder if will be available by visiting /default.htm

    Take a look through the express API and Connect Static middleware docs for more info.

提交回复
热议问题