Browse Source

move all `/api` endpoints to a separate router

pull/3/head
rozetko 2 years ago
parent
commit
0ac8f15e0e
  1. 13
      src/index.ts
  2. 16
      src/routes/api.ts

13
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, () => {

16
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));
Loading…
Cancel
Save