lighthouse.js/server/index.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

import bodyParser from 'koa-bodyparser';
import cors from '@koa/cors';
import Koa from 'koa';
import logger from 'koa-logger';
import helmet from 'koa-helmet';
import routing from './routes/';
import { port } from './config';
import winston from 'winston';
2019-10-15 00:04:47 +02:00
import Slack from 'node-slack';
require('winston-daily-rotate-file');
// 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-10-15 00:04:47 +02:00
const slackAPIKey = process.env.SLACK_HOOK_URL;
const mySlack = new Slack(slackAPIKey, {});
// Create Koa Application
const app = new Koa();
app
.use(logger())
.use(bodyParser())
.use(helmet())
.use(cors());
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}/`));
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',
});
}