From 0ac8f15e0eca5d601b5ee2f2e62907a369cb0271 Mon Sep 17 00:00:00 2001 From: rozetko Date: Wed, 28 Dec 2022 14:43:30 +0300 Subject: [PATCH] move all `/api` endpoints to a separate router --- src/index.ts | 13 +++---------- src/routes/api.ts | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 src/routes/api.ts diff --git a/src/index.ts b/src/index.ts index 73841bf..64fd506 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,24 +1,17 @@ -import { EXPORTED_PATH } from './config'; -import { router as tasksRouter } from './routes/tasks'; -import { router as statusRouter } from './routes/status'; -import { router as deleteRouter } from './routes/delete'; +import { router as apiRouter } from './routes/api'; import { port } from './config'; import * as express from 'express'; import * as bodyParser from 'body-parser'; + const app = express(); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); -// TODO: move everything with /api prefix to an apiRouter -app.use('/api/status', statusRouter); - -app.use('/api/tasks', tasksRouter); -app.use('/api/delete', deleteRouter); +app.use('/api', apiRouter); -app.use('/api/static', express.static(EXPORTED_PATH)); app.use('/', (req, res) => { res.send('Grafana-data-exporter server works') }); app.listen(port, () => { diff --git a/src/routes/api.ts b/src/routes/api.ts new file mode 100644 index 0000000..8e55309 --- /dev/null +++ b/src/routes/api.ts @@ -0,0 +1,16 @@ +import { EXPORTED_PATH } from '../config'; +import { router as tasksRouter } from '../routes/tasks'; +import { router as statusRouter } from '../routes/status'; +import { router as deleteRouter } from '../routes/delete'; + +import * as express from 'express'; + + +export const router = express.Router(); + +router.use('/status', statusRouter); + +router.use('/tasks', tasksRouter); +router.use('/delete', deleteRouter); + +router.use('/static', express.static(EXPORTED_PATH));