2017-08-16 19:49:27 +02:00
|
|
|
import bodyParser from 'koa-bodyparser';
|
2018-04-08 08:13:27 +02:00
|
|
|
import cors from '@koa/cors';
|
2017-08-16 19:49:27 +02:00
|
|
|
import Koa from 'koa';
|
|
|
|
import logger from 'koa-logger';
|
|
|
|
import helmet from 'koa-helmet';
|
|
|
|
import routing from './routes/';
|
|
|
|
import { port } from './config';
|
2017-08-17 18:11:53 +02:00
|
|
|
import winston from 'winston';
|
2018-10-28 07:28:24 +01:00
|
|
|
import slack from 'node-slack';
|
2018-06-28 14:24:00 +02:00
|
|
|
require('winston-daily-rotate-file');
|
2017-08-17 18:11:53 +02:00
|
|
|
|
|
|
|
// Setup logging
|
|
|
|
winston.remove(winston.transports.Console);
|
2017-08-18 10:16:29 +02:00
|
|
|
winston.add(winston.transports.Console, { colorize: true, timestamp: true, prettyPrint: true });
|
2019-07-08 21:03:12 +02:00
|
|
|
let slackAPIKey = process.env.SLACK_HOOK_URL;
|
|
|
|
let mySlack = new slack(slackAPIKey, {});
|
2017-08-16 19:49:27 +02:00
|
|
|
// Create Koa Application
|
|
|
|
const app = new Koa();
|
|
|
|
|
|
|
|
app
|
|
|
|
.use(logger())
|
|
|
|
.use(bodyParser())
|
2018-04-08 08:13:27 +02:00
|
|
|
.use(helmet())
|
|
|
|
.use(cors());
|
2017-08-16 19:49:27 +02:00
|
|
|
|
|
|
|
routing(app);
|
|
|
|
|
|
|
|
// Start the application
|
2018-10-28 07:28:24 +01:00
|
|
|
app.listen(port, () => logToSlack(`Lighthouse API server is running at http://localhost:${port}/`));
|
2017-08-16 19:49:27 +02:00
|
|
|
|
|
|
|
export default app;
|
2018-10-28 07:28:24 +01:00
|
|
|
|
|
|
|
export function logToSlack (message) {
|
|
|
|
winston.log('info', 'SentToSlack: ' + message);
|
|
|
|
mySlack.send({
|
|
|
|
text : message,
|
|
|
|
channel : '#lighthouse-status',
|
|
|
|
username : 'Lighthouse',
|
|
|
|
icon_emoji: 'lighthouse',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function logErrorToSlack (message) {
|
|
|
|
winston.log('error', 'SentToSlack: ' + message);
|
|
|
|
mySlack.send({
|
|
|
|
text : message,
|
|
|
|
channel : '#lighthouse-status',
|
|
|
|
username : 'Lighthouse',
|
|
|
|
icon_emoji: 'lighthouse',
|
|
|
|
});
|
|
|
|
}
|