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
|
|
|
/*!
|
2013-11-18 14:36:13 +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.
|
2013-11-18 14:36:13 +00:00
|
|
|
*/
|
2016-11-15 21:46:23 +00:00
|
|
|
'use strict';
|
2013-11-18 14:36:13 +00:00
|
|
|
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()
|
2013-11-18 14:36:13 +00:00
|
|
|
*/
|
|
|
|
function urlNotFound() {
|
|
|
|
return function raiseUrlNotFoundError(req, res, next) {
|
2019-10-07 09:45:34 +00:00
|
|
|
const error = new Error('Cannot ' + req.method + ' ' + req.url);
|
2013-11-18 14:36:13 +00:00
|
|
|
error.status = 404;
|
|
|
|
next(error);
|
2014-10-16 22:54:40 +00:00
|
|
|
};
|
2013-11-18 14:36:13 +00:00
|
|
|
}
|