|
|
@ -1,5 +1,6 @@ |
|
|
|
import * as express from 'express'; |
|
|
|
import * as Koa from 'koa'; |
|
|
|
import * as bodyParser from 'body-parser'; |
|
|
|
import * as Router from 'koa-router'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { router as anomaliesRouter } from './routes/anomalies'; |
|
|
|
import { router as anomaliesRouter } from './routes/anomalies'; |
|
|
|
import { router as segmentsRouter } from './routes/segments'; |
|
|
|
import { router as segmentsRouter } from './routes/segments'; |
|
|
@ -9,23 +10,28 @@ import { checkDataFolders } from './services/data'; |
|
|
|
|
|
|
|
|
|
|
|
checkDataFolders(); |
|
|
|
checkDataFolders(); |
|
|
|
|
|
|
|
|
|
|
|
const app = express(); |
|
|
|
var app = new Koa(); |
|
|
|
const PORT = process.env.HASTIC_PORT || 8000; |
|
|
|
const PORT = process.env.HASTIC_PORT || 8000; |
|
|
|
|
|
|
|
|
|
|
|
app.use(bodyParser.json()); |
|
|
|
app.use(async function(ctx) { |
|
|
|
app.use(bodyParser.urlencoded({ extended: true })); |
|
|
|
ctx.response.header('Access-Control-Allow-Origin', '*'); |
|
|
|
|
|
|
|
ctx.response.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS'); |
|
|
|
app.use(function (req, res, next) { |
|
|
|
ctx.response.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); |
|
|
|
res.header('Access-Control-Allow-Origin', '*'); |
|
|
|
|
|
|
|
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS'); |
|
|
|
|
|
|
|
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); |
|
|
|
|
|
|
|
next(); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
app.use('/anomalies', anomaliesRouter); |
|
|
|
var anRouter = new Router(); |
|
|
|
app.use('/segments', segmentsRouter); |
|
|
|
anRouter.use('/anomalies', anomaliesRouter.routes(), anomaliesRouter.allowedMethods()); |
|
|
|
app.use('/alerts', alertsRouter); |
|
|
|
|
|
|
|
app.use('/', (req, res) => res.send({ status: 'OK' })); |
|
|
|
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) => { |
|
|
|
|
|
|
|
ctx.body = { status: 'OK' }; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
app.listen(PORT, () => { |
|
|
|
app.listen(PORT, () => { |
|
|
|
console.log(`Server is running on :${PORT}`) |
|
|
|
console.log(`Server is running on :${PORT}`) |
|
|
|