egg
Version:
A web application framework for Node.js
26 lines (25 loc) • 716 B
JavaScript
//#region src/app/middleware/notfound.ts
var notfound_default = (options) => {
return async function notfound(ctx, next) {
await next();
if (ctx.status !== 404 || ctx.body) return;
ctx.status = 404;
if (ctx.acceptJSON) {
ctx.body = { message: "Not Found" };
return;
}
const notFoundHtml = "<h1>404 Not Found</h1>";
if (options.pageUrl && ctx.path === options.pageUrl) {
ctx.body = `${notFoundHtml}<p><pre><code>config.notfound.pageUrl(${options.pageUrl})</code></pre> is unimplemented</p>`;
return;
}
if (options.pageUrl) {
ctx.realStatus = 404;
ctx.redirect(options.pageUrl);
return;
}
ctx.body = notFoundHtml;
};
};
//#endregion
export { notfound_default as default };