-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All pages return 404 when using Express error handling #447
Comments
The problem here is in the way you're registering your middleware. In a kraken app, you register your middleware in a config file. If you In the case above, your 404 handler is handling everything, having been registered before the middleware configured by kraken. If you move it into the config and let kraken register it, all will be resolved. In a kraken app, your app's entry point (typically For example, the below is an application with a working route at // ========== index.js ==========
var kraken = require('kraken-js');
var express = require('express');
var app = express();
app.use(kraken());
app.listen(8000, function () {
console.log('listening ...');
});
// ========== routes.js ==========
module.exports = function (router) {
router.get('/works', function (req, res) {
res.send('this works');
});
};
// ========== lib/404.js ==========
module.exports = function () {
return function (req, res, next) {
res.status(404).send('uh oh');
};
};
// ========== lib/error.js ==========
module.exports = function () {
return function (err, req, res, next) {
res.status(500).send('unknown error');
};
};
// ========== config/config.json ==========
{
"middleware": {
"notFound": {
"priority": 130,
"module": "path:./lib/404"
},
"errorResponse": {
"priority": 140,
"module": "path:./lib/error"
}
}
} |
👍 nicely answered @jasisk |
Good explanation, thanks! I recommend describing this a bit more explicitly in the readme because Kraken handles middleware entirely different than Express, so pointing users to the Express docs could be a bit confusing. |
cc @jasisk close issue please 😄 |
After seeing that the
404
and500
modules are being deprecated, I tried to follow the suggested method of using Express's normal error handling.The Express FAQ says the following:
As expected, creating a Hello World app with just Express properly shows a 404 message for nonexistent routes and shows the working page at
localhost:3000/working
:However, creating a fresh Kraken project doing the same thing results in all routes returning 404s even if there are valid routes defined in the
controllers
folder:Attempting to add the error handler to
onconfig
also results in all routes returning 404:Is the only alternative to have duplicate error handlers in every single controller?
I also suggest that the proper method of error handling be documented in the readme, as it is currently very difficult to find up-to-date information on error handling in Kraken (especially for 500 errors).
The text was updated successfully, but these errors were encountered: