From f30262530d69687fdeac99602241e169bfe9c15a Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 21 Jan 2017 14:39:39 +0900 Subject: [PATCH] [Server] :v: --- src/api/server.ts | 7 +++++++ src/{web => api}/service/twitter.ts | 2 +- src/web/server.ts | 5 ----- 3 files changed, 8 insertions(+), 6 deletions(-) rename src/{web => api}/service/twitter.ts (93%) diff --git a/src/api/server.ts b/src/api/server.ts index 836ce1f8a..5f8de5719 100644 --- a/src/api/server.ts +++ b/src/api/server.ts @@ -53,4 +53,11 @@ endpoints.forEach(endpoint => app.post('/signup', require('./private/signup').default); app.post('/signin', require('./private/signin').default); +app.use((req, res, next) => { + res.locals.user = ((req.headers['cookie'] || '').match(/i=(!\w+)/) || [null, null])[1]; + next(); +}); + +require('./service/twitter')(app); + module.exports = app; diff --git a/src/web/service/twitter.ts b/src/api/service/twitter.ts similarity index 93% rename from src/web/service/twitter.ts rename to src/api/service/twitter.ts index d881055f7..606a11a71 100644 --- a/src/web/service/twitter.ts +++ b/src/api/service/twitter.ts @@ -14,7 +14,7 @@ module.exports = (app: express.Application) => { callbackUrl: config.url + '/tw/cb' }); - app.get(/\/connect:twitter/, async (req, res): Promise => { + app.get('connect/twitter', async (req, res): Promise => { if (res.locals.user == null) return res.send('plz signin'); const ctx = await twAuth.begin(); redis.set(res.locals.user, JSON.stringify(ctx)); diff --git a/src/web/server.ts b/src/web/server.ts index a1b7130ba..5bff450aa 100644 --- a/src/web/server.ts +++ b/src/web/server.ts @@ -28,9 +28,6 @@ app.use(compression()); */ app.use((req, res, next) => { res.header('X-Frame-Options', 'DENY'); - - res.locals.user = ((req.headers['cookie'] || '').match(/i=(!\w+)/) || [null, null])[1]; - next(); }); @@ -51,8 +48,6 @@ app.get(/\/api:meta/, require('./meta')); app.get(/\/api:url/, require('./service/url-preview')); app.post(/\/api:rss/, require('./service/rss-proxy')); -require('./service/twitter')(app); - /** * Subdomain */