您是否正在寻找这样的东西:
server.get /list\/[a-zA-Z]+/, (req,res,next) ->
document = docpad.getCollection('documents').findOne({relativeOutPath: 'index.html'});
docpad.serveDocument({
document: document,
req: req,
res: res,
next: next,
statusCode: 200
});
这是 docpad.coffee 文件中的一个事件(服务器扩展)。它拦截请求并根据正则表达式对其进行测试(很容易只是一个普通的 url)。用户将看到他们输入的 url,但将提供 index.html。
或者更接近您的情况:
server.post "*", (req,res,next) ->
#do stuff
docpad.coffee 里面
events:
# Server Extend
# Used to add our own custom routes to the server before the docpad routes are added
serverExtend: (opts) ->
# Extract the server from the options
{server} = opts
docpad = @docpad
# As we are now running in an event,
# ensure we are using the latest copy of the docpad configuraiton
# and fetch our urls from it
latestConfig = docpad.getConfig()
oldUrls = latestConfig.templateData.site.oldUrls or []
newUrl = latestConfig.templateData.site.url
server.post "*", (req,res,next) ->
#do stuff