loopback/server/middleware/url-not-found.js

26 lines
734 B
JavaScript
Raw Normal View History

2020-01-21 19:19:18 +00:00
// Copyright IBM Corp. 2014,2019. All Rights Reserved.
2016-05-03 22:50:21 +00:00
// Node module: loopback
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
2014-06-05 00:42:18 +00:00
/*!
* Export the middleware.
2014-06-05 00:42:18 +00:00
* See discussion in Connect pull request #954 for more details
* https://github.com/senchalabs/connect/pull/954.
*/
'use strict';
module.exports = urlNotFound;
/**
* Convert any request not handled so far to a 404 error
* to be handled by error-handling middleware.
2014-06-05 00:42:18 +00:00
* @header loopback.urlNotFound()
*/
function urlNotFound() {
return function raiseUrlNotFoundError(req, res, next) {
const error = new Error('Cannot ' + req.method + ' ' + req.url);
error.status = 404;
next(error);
2014-10-16 22:54:40 +00:00
};
}