aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/oauth-clients.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-25 11:55:06 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-26 09:11:38 +0200
commiteb08047657e739bcd9e592d76307befa3998482b (patch)
treefc309f51ece792fd4307c4af510710a853e1d6b2 /server/controllers/api/oauth-clients.ts
parent5f04dd2f743961e0a06c29531cc3ccc9e4928d56 (diff)
downloadPeerTube-eb08047657e739bcd9e592d76307befa3998482b.tar.gz
PeerTube-eb08047657e739bcd9e592d76307befa3998482b.tar.zst
PeerTube-eb08047657e739bcd9e592d76307befa3998482b.zip
Use async/await in controllers
Diffstat (limited to 'server/controllers/api/oauth-clients.ts')
-rw-r--r--server/controllers/api/oauth-clients.ts26
1 files changed, 13 insertions, 13 deletions
diff --git a/server/controllers/api/oauth-clients.ts b/server/controllers/api/oauth-clients.ts
index f7dac598c..ac1ee9e36 100644
--- a/server/controllers/api/oauth-clients.ts
+++ b/server/controllers/api/oauth-clients.ts
@@ -2,15 +2,18 @@ import * as express from 'express'
2 2
3import { CONFIG } from '../../initializers' 3import { CONFIG } from '../../initializers'
4import { logger } from '../../helpers' 4import { logger } from '../../helpers'
5import { asyncMiddleware } from '../../middlewares'
5import { database as db } from '../../initializers/database' 6import { database as db } from '../../initializers/database'
6import { OAuthClientLocal } from '../../../shared' 7import { OAuthClientLocal } from '../../../shared'
7 8
8const oauthClientsRouter = express.Router() 9const oauthClientsRouter = express.Router()
9 10
10oauthClientsRouter.get('/local', getLocalClient) 11oauthClientsRouter.get('/local',
12 asyncMiddleware(getLocalClient)
13)
11 14
12// Get the client credentials for the PeerTube front end 15// Get the client credentials for the PeerTube front end
13function getLocalClient (req: express.Request, res: express.Response, next: express.NextFunction) { 16async function getLocalClient (req: express.Request, res: express.Response, next: express.NextFunction) {
14 const serverHostname = CONFIG.WEBSERVER.HOSTNAME 17 const serverHostname = CONFIG.WEBSERVER.HOSTNAME
15 const serverPort = CONFIG.WEBSERVER.PORT 18 const serverPort = CONFIG.WEBSERVER.PORT
16 let headerHostShouldBe = serverHostname 19 let headerHostShouldBe = serverHostname
@@ -24,17 +27,14 @@ function getLocalClient (req: express.Request, res: express.Response, next: expr
24 return res.type('json').status(403).end() 27 return res.type('json').status(403).end()
25 } 28 }
26 29
27 db.OAuthClient.loadFirstClient() 30 const client = await db.OAuthClient.loadFirstClient()
28 .then(client => { 31 if (!client) throw new Error('No client available.')
29 if (!client) throw new Error('No client available.') 32
30 33 const json: OAuthClientLocal = {
31 const json: OAuthClientLocal = { 34 client_id: client.clientId,
32 client_id: client.clientId, 35 client_secret: client.clientSecret
33 client_secret: client.clientSecret 36 }
34 } 37 return res.json(json)
35 res.json(json)
36 })
37 .catch(err => next(err))
38} 38}
39 39
40// --------------------------------------------------------------------------- 40// ---------------------------------------------------------------------------