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));