E
E
Egor2014-02-15 21:19:09
Node.js
Egor, 2014-02-15 21:19:09

Node.js Express 3.0: handling missing static file

Good day.
Express config is like this

app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({key:'session',secret:'123456789',cookie:{maxAge:86400000}}));
app.use(app.router);
app.use(express.static(__dirname+'/view'));
app.use(express.errorHandler);

If a static page uses a file that is not on the server, then the page goes into endless loading.
Tell me how to solve this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Pushkarev, 2014-02-15
@ByKraB

After app.use express.static , insert a middleware that will return a 404 error. For example, like this:

app.use(function(req, res){
  res.send(404, 'Sorry, we cannot find that!');
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question