assetflow/src/routes/index.ts
2023-06-06 23:02:19 +02:00

26 lines
781 B
TypeScript

import express, { Express } from 'express';
import { __path, prisma } from '../index.js';
// Route imports
import frontend_routes from './frontend/index.js';
import static_routes from './static/index.js';
import api_routes from './api/index.js';
const Router = express.Router({ strict: false });
Router.use('/static', static_routes);
Router.use('/api', api_routes);
Router.use('/', frontend_routes);
// Default route.
Router.all('*', function (req, res) {
// TODO: Respond based on content-type (with req.is('application/json'))
if (req.is('application/json')) {
res.status(404).json({ errorcode: 'NOT_FOUND', error: 'Not Found!' });
} else {
res.status(404).render(__path + '/src/frontend/errors/404.eta.html', { url: req.originalUrl });
}
});
export default Router;