[英]Express Serving Static Files
I'm just learning how to use Express, and am trying to serve the static files, like the bootstrap.min.css file. 我正在学习如何使用Express,并尝试提供静态文件,例如bootstrap.min.css文件。
Here's my folder structure: 这是我的文件夹结构:
server.js
/server
/includes
layout.jade
/public
/css
/vendor
/bootstrap
/dist
/css
bootstrap.min.css
/views
index.jade
I'm using wiredep
in my Gulpfile.js, and have tried several different variations of the configuration, and haven't gotten anything. 我在wiredep
中使用wiredep
,并尝试了几种不同的配置变体,但是什么也没得到。 Here's my server.js file: 这是我的server.js文件:
var express = require('express');
var app = express();
var env = process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var port = process.env.PORT || 5000;
app.use('/server', express.static('public'));
app.set('views', './server/views');
app.set('view engine', 'jade');
require('./server/routes/routes')(app);
app.listen(port, function(err) {
console.log('running server on port: ' + port);
});
I've tried a couple different ways setting the express.static
part, but again, it isn't serving the static files. 我尝试了几种不同的方式来设置express.static
部分,但是同样,它不提供静态文件。
Any help would be greatly appreciated. 任何帮助将不胜感激。
Try: 尝试:
app.use(express.static(__dirname + '/server/public'));
on link tag 在链接标签上
href = "vendor/bootstrap/dist/css/bootstrap.min.css"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.