express版本是3.2.5,ejs版本是0.8.4
我想服务stylesheets/style.css
我正在这样做app.js
app.use(express.static(path.join(__dirname, 'public')));
app.use(app.router);
// render article.ejs
app.get('/u/:name/:day/:title', function(req,res){
Post.getOne(req.params.name, req.params.day, req.params.title, function(err, post){
if(err){
req.flash('error',err);
return res.redirect('/');
}
res.render('article',{
title: req.params.title,
post: post,
user: req.session.user,
success: req.flash('success').toString(),
error: req.flash('error').toString()
});
});
});
我的结构是header.ejs
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Blog</title>
<link rel="stylesheet" href="stylesheets/style.css">
</head>
<body>
article.ejs
内容是
<%- include header %>
<p class="info">
author:<a href="/u/<%= post.name %>"><%= post.name %></a> |
date:<%= post.time.minute %>
</p>
<p><%- post.post %></p>
<%- include comment %>
<%- include footer %>
当我访问http://localhost:3000/
GET /stylesheets/style.css 304 9ms
访问时localhost:3000/u/username/date/postname
GET /u/username/date/stylesheets/style.css 404 10ms
为什么它显示这个/u/username/date/stylesheets/style.css
目录
有任何想法吗?