diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-03-29 20:34:39 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-03-29 20:34:39 +0900 |
| commit | 7228e6d11178dfa715fc2ae4e834dec129248214 (patch) | |
| tree | 8a6224fa578501d67387da8129fd06932f7a818a /src/server/api/index.ts | |
| parent | 整理した (diff) | |
| download | sharkey-7228e6d11178dfa715fc2ae4e834dec129248214.tar.gz sharkey-7228e6d11178dfa715fc2ae4e834dec129248214.tar.bz2 sharkey-7228e6d11178dfa715fc2ae4e834dec129248214.zip | |
:v:
Diffstat (limited to 'src/server/api/index.ts')
| -rw-r--r-- | src/server/api/index.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/server/api/index.ts b/src/server/api/index.ts new file mode 100644 index 0000000000..e89d196096 --- /dev/null +++ b/src/server/api/index.ts @@ -0,0 +1,55 @@ +/** + * API Server + */ + +import * as express from 'express'; +import * as bodyParser from 'body-parser'; +import * as cors from 'cors'; +import * as multer from 'multer'; + +// import authenticate from './authenticate'; +import endpoints from './endpoints'; + +/** + * Init app + */ +const app = express(); + +app.disable('x-powered-by'); +app.set('etag', false); +app.use(bodyParser.urlencoded({ extended: true })); +app.use(bodyParser.json({ + type: ['application/json', 'text/plain'], + verify: (req, res, buf, encoding) => { + if (buf && buf.length) { + (req as any).rawBody = buf.toString(encoding || 'utf8'); + } + } +})); +app.use(cors()); + +app.get('/', (req, res) => { + res.send('YEE HAW'); +}); + +/** + * Register endpoint handlers + */ +endpoints.forEach(endpoint => + endpoint.withFile ? + app.post(`/${endpoint.name}`, + endpoint.withFile ? multer({ storage: multer.diskStorage({}) }).single('file') : null, + require('./api-handler').default.bind(null, endpoint)) : + app.post(`/${endpoint.name}`, + require('./api-handler').default.bind(null, endpoint)) +); + +app.post('/signup', require('./private/signup').default); +app.post('/signin', require('./private/signin').default); + +require('./service/github')(app); +require('./service/twitter')(app); + +require('./bot/interfaces/line')(app); + +module.exports = app; |