Skip to content

Commit

Permalink
feat: redirect when missing route to web page
Browse files Browse the repository at this point in the history
  • Loading branch information
Asadaaaaa committed Oct 6, 2023
1 parent 122ebce commit 71674ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ class Server {

run() {
this.API = Express();
const middlewareHandler = new MiddlewareHandler(this);

new MiddlewareHandler(this);
middlewareHandler.global();
new RouteHandler(this);
middlewareHandler.missingRoute();


this.API.listen(this.env.PORT, this.env.IP, () => this.sendLogs('Server Started, Listening PORT ' + this.env.PORT));
}
Expand Down
9 changes: 7 additions & 2 deletions src/middlewares/Handler.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class Handler {
this.API = this.server.API;

this.ResponsePreset = new ResponsePreset();

this.global();
}

global() {
Expand Down Expand Up @@ -107,6 +105,13 @@ class Handler {
}));
}
}

missingRoute() {
this.API.get('*', (req, res) => {
// Redirect to the desired URL
res.redirect(`${this.server.env.WEB_HOST}/not-found`);
});
}
}

export default Handler;

0 comments on commit 71674ff

Please sign in to comment.