summaryrefslogtreecommitdiff
path: root/src/server/api/server.ts
diff options
context:
space:
mode:
authorAkihiko Odaki <nekomanma@pixiv.co.jp>2018-03-29 01:20:40 +0900
committerAkihiko Odaki <nekomanma@pixiv.co.jp>2018-03-29 01:54:41 +0900
commit90f8fe7e538bb7e52d2558152a0390e693f39b11 (patch)
tree0f830887053c8f352b1cd0c13ca715fd14c1f030 /src/server/api/server.ts
parentImplement remote account resolution (diff)
downloadsharkey-90f8fe7e538bb7e52d2558152a0390e693f39b11.tar.gz
sharkey-90f8fe7e538bb7e52d2558152a0390e693f39b11.tar.bz2
sharkey-90f8fe7e538bb7e52d2558152a0390e693f39b11.zip
Introduce processor
Diffstat (limited to 'src/server/api/server.ts')
-rw-r--r--src/server/api/server.ts55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/server/api/server.ts b/src/server/api/server.ts
new file mode 100644
index 0000000000..e89d196096
--- /dev/null
+++ b/src/server/api/server.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;