Default route(404) is now Content-Type aware(json)

- Cleanup
This commit is contained in:
Leon Meier 2023-05-15 02:08:43 +02:00
parent 9c4eb3200e
commit b1a73ebd4a
2 changed files with 7 additions and 6 deletions

View File

@ -44,7 +44,6 @@ export const prisma = new PrismaClient({
export const app = express(); export const app = express();
app.set('x-powered-by', false); app.set('x-powered-by', false);
//app.set('strict routing', true);
app.engine('html', eta.renderFile); app.engine('html', eta.renderFile);
// app.use(cors()); // app.use(cors());
@ -54,10 +53,8 @@ app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json()); app.use(bodyParser.json());
app.use(fileUpload()); app.use(fileUpload());
// Configure static https://expressjs.com/de/starter/static-files.html
// app.use('/static', express.static('public'));
app.use(express.static(__path + '/static')); app.use(express.static(__path + '/static'));
app.use(routes); app.use(routes);
app.listen(config.global.http_port, config.global.http_listen_address, () => { app.listen(config.global.http_port, config.global.http_listen_address, () => {

View File

@ -13,9 +13,13 @@ Router.use('/api', api_routes);
Router.use('/', frontend_routes); Router.use('/', frontend_routes);
// Default route. // Default route.
Router.get('*', function (req, res) { Router.all('*', function (req, res) {
// TODO: Respond based on content-type (with req.is('application/json')) // TODO: Respond based on content-type (with req.is('application/json'))
res.status(404).render(__path + '/src/frontend/errors/404.eta.html', { url: req.originalUrl }); if (req.is('application/json')) {
res.status(404).json({ errorcode: '404' });
} else {
res.status(404).render(__path + '/src/frontend/errors/404.eta.html', { url: req.originalUrl });
}
}); });
export default Router; export default Router;