diff --git a/src/app.ts b/src/app.ts index 73eea5f..768ac51 100644 --- a/src/app.ts +++ b/src/app.ts @@ -4,6 +4,7 @@ import consola from 'consola'; import * as jwt from 'jsonwebtoken'; import { createConnection } from 'typeorm'; import 'reflect-metadata'; +import { router as routerMain } from './routes/index'; // const loaders = require('./loaders'); import * as loaders from './loaders/index'; @@ -17,12 +18,8 @@ createConnection() consola.error(err); }) .finally(() => { - app.get('/', (req, res) => { - const encoded = jwt.sign({ key: 'value' }, 'secret'); - consola.info(encoded); - return res.send('Express + TypeScript Server'); - }); // await loaders.init(app); + app.use('/api/', routerMain); app.listen(PORT, () => { consola.success(`⚡️[server]: Server is running at http://localhost:${PORT}`); }); diff --git a/src/routes/index.ts b/src/routes/index.ts new file mode 100644 index 0000000..1dc658e --- /dev/null +++ b/src/routes/index.ts @@ -0,0 +1,9 @@ +import express from 'express'; +const router = express.Router(); +router.use('/v1/', (req, res) => { + return res.send('Express + TypeScript Server'); +}); +router.use('*', (req, res) => { + return res.status(404).send('404'); +}); +export { router };