|
|
@ -14,28 +14,30 @@ import * as Koa from 'koa'; |
|
|
|
import * as Router from 'koa-router'; |
|
|
|
import * as Router from 'koa-router'; |
|
|
|
import * as bodyParser from 'koa-bodyparser'; |
|
|
|
import * as bodyParser from 'koa-bodyparser'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
init(); |
|
|
|
|
|
|
|
|
|
|
|
AnalyticsController.init(); |
|
|
|
async function init() { |
|
|
|
ProcessService.registerExitHandler(AnalyticsController.terminate); |
|
|
|
await convertPanelUrlToPanelId(); |
|
|
|
convertPanelUrlToPanelId(); |
|
|
|
AnalyticsController.init(); |
|
|
|
|
|
|
|
ProcessService.registerExitHandler(AnalyticsController.terminate); |
|
|
|
|
|
|
|
|
|
|
|
var app = new Koa(); |
|
|
|
const app = new Koa(); |
|
|
|
|
|
|
|
|
|
|
|
app.on('error', (err, ctx) => { |
|
|
|
app.on('error', (err, ctx) => { |
|
|
|
console.log('got server error:'); |
|
|
|
console.log('got server error:'); |
|
|
|
console.log(err); |
|
|
|
console.log(err); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.use(bodyParser()) |
|
|
|
app.use(bodyParser()) |
|
|
|
|
|
|
|
|
|
|
|
app.use(async function(ctx, next) { |
|
|
|
app.use(async function(ctx, next) { |
|
|
|
ctx.set('Access-Control-Allow-Origin', '*'); |
|
|
|
ctx.set('Access-Control-Allow-Origin', '*'); |
|
|
|
ctx.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS'); |
|
|
|
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'); |
|
|
|
ctx.set('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); |
|
|
|
await next(); |
|
|
|
await next(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
app.use(async function(ctx, next) { |
|
|
|
app.use(async function(ctx, next) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
await next(); |
|
|
|
await next(); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
@ -46,15 +48,15 @@ app.use(async function(ctx, next) { |
|
|
|
message: `${ctx.method} ${ctx.url} error: ${e.message}` |
|
|
|
message: `${ctx.method} ${ctx.url} error: ${e.message}` |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var rootRouter = new Router(); |
|
|
|
const rootRouter = new Router(); |
|
|
|
rootRouter.use('/analyticUnits', analyticUnitsRouter.routes(), analyticUnitsRouter.allowedMethods()); |
|
|
|
rootRouter.use('/analyticUnits', analyticUnitsRouter.routes(), analyticUnitsRouter.allowedMethods()); |
|
|
|
rootRouter.use('/segments', segmentsRouter.routes(), segmentsRouter.allowedMethods()); |
|
|
|
rootRouter.use('/segments', segmentsRouter.routes(), segmentsRouter.allowedMethods()); |
|
|
|
rootRouter.use('/threshold', thresholdRouter.routes(), thresholdRouter.allowedMethods()); |
|
|
|
rootRouter.use('/threshold', thresholdRouter.routes(), thresholdRouter.allowedMethods()); |
|
|
|
|
|
|
|
|
|
|
|
rootRouter.get('/', async (ctx) => { |
|
|
|
rootRouter.get('/', async (ctx) => { |
|
|
|
const activeWebhooks = await AnalyticsController.getActiveWebhooks(); |
|
|
|
const activeWebhooks = await AnalyticsController.getActiveWebhooks(); |
|
|
|
|
|
|
|
|
|
|
|
ctx.response.body = { |
|
|
|
ctx.response.body = { |
|
|
@ -74,13 +76,13 @@ rootRouter.get('/', async (ctx) => { |
|
|
|
activeWebhooks: activeWebhooks.length, |
|
|
|
activeWebhooks: activeWebhooks.length, |
|
|
|
timestamp: new Date(Date.now()) |
|
|
|
timestamp: new Date(Date.now()) |
|
|
|
}; |
|
|
|
}; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
app |
|
|
|
app |
|
|
|
.use(rootRouter.routes()) |
|
|
|
.use(rootRouter.routes()) |
|
|
|
.use(rootRouter.allowedMethods()); |
|
|
|
.use(rootRouter.allowedMethods()); |
|
|
|
|
|
|
|
|
|
|
|
app.listen(HASTIC_PORT, () => { |
|
|
|
app.listen(HASTIC_PORT, () => { |
|
|
|
console.log(`Server is running on :${HASTIC_PORT}`); |
|
|
|
console.log(`Server is running on :${HASTIC_PORT}`); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|