Answer the question
In order to leave comments, you need to log in
Node.js, Express and 404s?
Problem:
Using Express to mirror my page for errors.
Here's what I tried:
var express = require('express');
var app = module.exports = express.createServer();
var util = require('util');
// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
// Routes
app.get('/', function(req, res){
res.render('index', {
title: 'Express'
});
});
app.listen(3000);
app.error(function(err, req, res, next){
console.log('Error!');
res.render('404.jade', {
title: '404 — Page maybe not found'
});
//next(err);
});
Answer the question
In order to leave comments, you need to log in
yeah, it didn’t work either, I tried examples from the docks and looked here github.com/visionmedia/express/tree/master/examples .
I just made a page app.get('/404',…, in the nginx settings I wrote that I have 404 at this address, and in the express code, because I have to describe everything, otherwise it will fall, I just do res.redirect('/404 ')
Works from this example: github.com/visionmedia/express/blob/master/examples/error-pages/app.js
app.get('/*', function(req, res){
res.status(404);
res.render('404', {
title: 'Express'
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question