diff options
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 | // --------------------------------------------------------------------------- |