(node:26906) UnhandledPromiseRejectionWarning: ReferenceError: err is not defined
at universalAdapter (/Users/chriscalo/Projects/viaticus/node_modules/@universal-adapter/express/ExpressAdapter.js:24:12)
(node:26906) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handl
ed with .catch(). (rejection id: 2)
(node:26906) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Then I tried a different approach of redirecting to /404?method=get&url=/path/that/doesn't/exist/. This works, but I don't love this approach because the URL changes. Here's my main server:
import express from "express";
import { start } from "express-start";
import authServer from "./auth";
import apiServer from "~/api";
import pagesServer from "~/pages";
import goldpageServer from "./goldpage";
import staticServer from "./static-server";
import notFoundServer from "./not-found";
export const server = express();
server.enable("trust proxy");
server.use(
authServer,
apiServer,
pagesServer,
goldpageServer,
staticServer,
notFoundServer,
);
if (process.mainModule === module) {
start(server);
}
And here's not-found.js:
import path from "path";
import express from "express";
export const server = express();
export default server;
// catch-all server for all unhandled requests
// must be the last handler because it always redirects!
server.use((req, res, next) => {
res.redirect(`/404?method=${req.method}&url=${req.url}`)
});
Is there a cleaner way to get a catch-all 404.page.js working?
I want to have my last express handler always render
404.page.js
&404.vue
. I tried using a catch-allroute
in my404.page.js
file:But I end up getting the following error:
Then I tried a different approach of redirecting to
/404?method=get&url=/path/that/doesn't/exist/
. This works, but I don't love this approach because the URL changes. Here's my main server:And here's
not-found.js
:Is there a cleaner way to get a catch-all
404.page.js
working?