在我的快递应用中,静态资产不会在something/something
上投放。
/**
* Express configuration.
*/
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.engine('handlebars', exphbs({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');
// app.use(compress());
// app.use(assets({
// paths: ['public/css', 'public/js']
// }));
app.use(logger('dev'));
app.use(favicon(path.join(__dirname, 'public/favicon.png')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(expressValidator());
app.use(methodOverride());
app.use(cookieParser());
app.use(session({
resave: true,
saveUninitialized: true,
secret: secrets.sessionSecret,
store: new MongoStore({ url: secrets.db, autoReconnect: true })
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.use(lusca({
csrf: true,
xframe: 'SAMEORIGIN',
xssProtection: true
}));
app.use(function(req, res, next) {
res.locals.user = req.user;
next();
});
app.use(function(req, res, next) {
if (/api/i.test(req.path)) req.session.returnTo = req.path;
next();
});
app.use(express.static(__dirname + '/assets'));
然后在我的主要布局
<link rel="stylesheet" href="css/main.css">
主页有效,但不是嵌套路由吗?