diff --git a/src/index.ts b/src/index.ts index fe008d1..9717894 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,7 +44,6 @@ export const prisma = new PrismaClient({ export const app = express(); app.set('x-powered-by', false); -//app.set('strict routing', true); app.engine('html', eta.renderFile); // app.use(cors()); @@ -54,10 +53,8 @@ app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); 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(routes); app.listen(config.global.http_port, config.global.http_listen_address, () => { diff --git a/src/routes/index.ts b/src/routes/index.ts index 11ddf8b..822817b 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -13,9 +13,13 @@ Router.use('/api', api_routes); Router.use('/', frontend_routes); // Default route. -Router.get('*', function (req, res) { +Router.all('*', function (req, res) { // 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;