From 216e618e5571d1f41d78e0a2e70233b38a2732c3 Mon Sep 17 00:00:00 2001 From: Alexey Velikiy Date: Tue, 29 May 2018 15:04:51 +0300 Subject: [PATCH] rootroute --- server/src/index.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/server/src/index.ts b/server/src/index.ts index 87a09d5..78db2bd 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -14,25 +14,23 @@ var app = new Koa(); const PORT = process.env.HASTIC_PORT || 8000; app.use(async function(ctx) { - ctx.response.header('Access-Control-Allow-Origin', '*'); - ctx.response.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS'); - ctx.response.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); + ctx.set('Access-Control-Allow-Origin', '*'); + ctx.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS'); + ctx.set('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); }); -var anRouter = new Router(); -anRouter.use('/anomalies', anomaliesRouter.routes(), anomaliesRouter.allowedMethods()); - -var seRouter = new Router(); -anRouter.use('/segments', segmentsRouter.routes(), segmentsRouter.allowedMethods()); - -var seRouter = new Router(); -anRouter.use('/alerts', alertsRouter.routes(), alertsRouter.allowedMethods()); - -var rootRoute = new Router(); -rootRoute.get('/', async (ctx) => { +var rootRouter = new Router(); +rootRouter.use('/anomalies', anomaliesRouter.routes(), anomaliesRouter.allowedMethods()); +rootRouter.use('/segments', segmentsRouter.routes(), segmentsRouter.allowedMethods()); +rootRouter.use('/alerts', alertsRouter.routes(), alertsRouter.allowedMethods()); +rootRouter.get('/', async (ctx) => { ctx.body = { status: 'OK' }; }); +app + .use(rootRouter.routes()) + .use(rootRouter.allowedMethods()) + app.listen(PORT, () => { console.log(`Server is running on :${PORT}`) });