0

私は現在、nodejs で webapp に取り組んでいます。エクスプレスフレームワークでcompoundjsを使用しています。

routes.js だけを使用して 404 ページを配置するにはどうすればよいですか? そうするための適切なドキュメントはありません。

使用できないコントローラー アクションを処理したいだけです。私にはできません。

前もって感謝します。

4

1 に答える 1

1

詳細は 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');
    });
于 2014-02-25T11:37:53.600 に答える