문제

현재 NodeJS의 WebApp에서 작업하고 있습니다.나는 익스프레스 프레임 워크를 통해 복합자를 사용하고 있습니다.

routes.js를 사용하여 404 페이지를 어떻게 넣을 수 있습니까?그렇게 할 적절한 문서가 없습니다.

i 불가능한 컨트롤러 작업을 처리하고자합니다.내가 할 수없는 것은 할 수 없다.

미리 감사드립니다.

도움이 되었습니까?

해결책

세부 정보는 express 예제 :

// Error handlers

// Since this is the last non-error-handling
// middleware use()d, we assume 404, as nothing else
// responded.

// $ curl http://localhost:3000/notfound
// $ curl http://localhost:3000/notfound -H "Accept: application/json"
// $ curl http://localhost:3000/notfound -H "Accept: text/plain"

    app.use(function(req, res, next){
      res.status(404);

      // respond with html page
      if (req.accepts('html')) {
        res.render('404', { url: req.url });
        return;
      }

      // respond with json
      if (req.accepts('json')) {
        res.send({ error: 'Not found' });
        return;
      }

      // default to plain-text. send()
      res.type('txt').send('Not found');
    });
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top