2014-02-28 2 views
0

이것은 정말 분명해야하지만 주위를 둘러 보지 않아야합니다.Docpad에서 경로를 처리하는 방법

도큐멘트에 추가 경로는 어떻게 추가합니까?

임에 Docpad 동등한 찾고 express.js의 지금까지 내가 이것에 대한 플러그인 모듈을 만들 필요가 이해할 수

app.post("*", function(res,req,next){ 
//Do stuff 
} 

? 내 경로를 사용하려면 어떻게해야합니까? 그것은 extend-server 이벤트와 관련이 있다고 추측합니다. docpad.coffee에 매개 변수로 넣을 수 있습니까?

경로 처리기에 req 객체를 전달하려면 어떻게해야합니까?

나는 항상 내 라우팅을 먼저 고려해야 만합니까? 어떤 미들웨어 같습니까? (처리 된) URL을 docpads 표준 라우팅으로 다시 전달할 수 있습니까? 방법?

답변

1

당신은 이런 식으로 뭔가를 찾고 계십니까 :

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 파일에. 그것의 요청을 가로 챈 다음 regex에 대해 테스트합니다 (쉽게 일반 URL 일 수 있음). 사용자는 입력 한 URL을 볼 수 있지만 index.html이 제공됩니다.

또는 귀하의 경우에 더 가까이 : 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 
내부

server.post "*", (req,res,next) -> 
       #do stuff 

관련 문제