2016-12-29 00:49:51 +02:00
|
|
|
/**
|
|
|
|
* API Server
|
|
|
|
*/
|
|
|
|
|
|
|
|
import * as express from 'express';
|
|
|
|
import * as bodyParser from 'body-parser';
|
|
|
|
import * as cors from 'cors';
|
|
|
|
import * as multer from 'multer';
|
|
|
|
|
2016-12-29 02:57:07 +02:00
|
|
|
// import authenticate from './authenticate';
|
2016-12-29 00:49:51 +02:00
|
|
|
import endpoints from './endpoints';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init app
|
|
|
|
*/
|
|
|
|
const app = express();
|
|
|
|
|
|
|
|
app.disable('x-powered-by');
|
|
|
|
app.set('etag', false);
|
|
|
|
app.use(bodyParser.urlencoded({ extended: true }));
|
2017-02-11 19:18:58 +02:00
|
|
|
app.use(bodyParser.json({
|
2017-10-06 22:30:57 +03:00
|
|
|
type: ['application/json', 'text/plain'],
|
|
|
|
verify: (req, res, buf, encoding) => {
|
|
|
|
if (buf && buf.length) {
|
|
|
|
(req as any).rawBody = buf.toString(encoding || 'utf8');
|
|
|
|
}
|
|
|
|
}
|
2017-02-11 19:18:58 +02:00
|
|
|
}));
|
2017-12-10 11:08:28 +02:00
|
|
|
app.use(cors());
|
2016-12-29 00:49:51 +02:00
|
|
|
|
2016-12-29 19:17:30 +02:00
|
|
|
app.get('/', (req, res) => {
|
|
|
|
res.send('YEE HAW');
|
|
|
|
});
|
|
|
|
|
2016-12-29 00:49:51 +02:00
|
|
|
/**
|
|
|
|
* Register endpoint handlers
|
|
|
|
*/
|
|
|
|
endpoints.forEach(endpoint =>
|
|
|
|
endpoint.withFile ?
|
2017-04-14 14:45:37 +03:00
|
|
|
app.post(`/${endpoint.name}`,
|
2017-11-13 22:26:27 +02:00
|
|
|
endpoint.withFile ? multer({ storage: multer.diskStorage({}) }).single('file') : null,
|
2016-12-29 00:49:51 +02:00
|
|
|
require('./api-handler').default.bind(null, endpoint)) :
|
2017-04-14 14:45:37 +03:00
|
|
|
app.post(`/${endpoint.name}`,
|
2016-12-29 00:49:51 +02:00
|
|
|
require('./api-handler').default.bind(null, endpoint))
|
|
|
|
);
|
|
|
|
|
|
|
|
app.post('/signup', require('./private/signup').default);
|
|
|
|
app.post('/signin', require('./private/signin').default);
|
|
|
|
|
2017-02-11 23:03:04 +02:00
|
|
|
require('./service/github')(app);
|
2017-01-21 07:39:39 +02:00
|
|
|
require('./service/twitter')(app);
|
|
|
|
|
2017-10-06 21:36:46 +03:00
|
|
|
require('./bot/interfaces/line')(app);
|
|
|
|
|
2016-12-29 00:49:51 +02:00
|
|
|
module.exports = app;
|