diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-25 11:55:06 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-26 09:11:38 +0200 |
commit | eb08047657e739bcd9e592d76307befa3998482b (patch) | |
tree | fc309f51ece792fd4307c4af510710a853e1d6b2 /server/controllers/api/oauth-clients.ts | |
parent | 5f04dd2f743961e0a06c29531cc3ccc9e4928d56 (diff) | |
download | PeerTube-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.ts | 26 |
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 | ||
3 | import { CONFIG } from '../../initializers' | 3 | import { CONFIG } from '../../initializers' |
4 | import { logger } from '../../helpers' | 4 | import { logger } from '../../helpers' |
5 | import { asyncMiddleware } from '../../middlewares' | ||
5 | import { database as db } from '../../initializers/database' | 6 | import { database as db } from '../../initializers/database' |
6 | import { OAuthClientLocal } from '../../../shared' | 7 | import { OAuthClientLocal } from '../../../shared' |
7 | 8 | ||
8 | const oauthClientsRouter = express.Router() | 9 | const oauthClientsRouter = express.Router() |
9 | 10 | ||
10 | oauthClientsRouter.get('/local', getLocalClient) | 11 | oauthClientsRouter.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 |
13 | function getLocalClient (req: express.Request, res: express.Response, next: express.NextFunction) { | 16 | async 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 | // --------------------------------------------------------------------------- |