-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
executable file
·36 lines (27 loc) · 1.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require('newrelic');
import express from 'express';
import bodyParser from 'body-parser';
import logger, { expressLog, expressErrorLog } from 'logger';
import healthMiddleware from './middlewares/health';
import buildRoute from './router';
// This is your bot's router
import yourBotMessengerRouter from './bot/platforms/messenger/bot-name/router-builder';
const IS_PRODUCTION = process.env.NODE_ENV === 'production';
if (!IS_PRODUCTION) {
require('source-map-support/register');
}
const app = express();
const router = express.Router();
const server = require('http').Server(app);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(expressLog);
app.use(expressErrorLog);
// Health check endpoint, '/_ah/health' required for Google App Engine
app.use('/_ah/health', healthMiddleware);
// This route should be in the messenger webhook
buildRoute(router, '/messenger/yourbot', yourBotMessengerRouter, {});
app.use(router);
const listener = server.listen(process.env.PORT || 8080, () => {
logger.debug(`Server started at port ${listener.address().port}`);
});