X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Foauth-clients.ts;h=ac1ee9e36f44cf481c151d15d8861ff37c09feaa;hb=fcaf1e0aa84213a1b1f1b1a44a3276eae35ebe70;hp=f7dac598c3d62770049ca656bc27f8d35c9973a0;hpb=6fcd19ba737f1f5614a56c6925adb882dea43b8d;p=github%2FChocobozzz%2FPeerTube.git 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' import { CONFIG } from '../../initializers' import { logger } from '../../helpers' +import { asyncMiddleware } from '../../middlewares' import { database as db } from '../../initializers/database' import { OAuthClientLocal } from '../../../shared' const oauthClientsRouter = express.Router() -oauthClientsRouter.get('/local', getLocalClient) +oauthClientsRouter.get('/local', + asyncMiddleware(getLocalClient) +) // Get the client credentials for the PeerTube front end -function getLocalClient (req: express.Request, res: express.Response, next: express.NextFunction) { +async function getLocalClient (req: express.Request, res: express.Response, next: express.NextFunction) { const serverHostname = CONFIG.WEBSERVER.HOSTNAME const serverPort = CONFIG.WEBSERVER.PORT let headerHostShouldBe = serverHostname @@ -24,17 +27,14 @@ function getLocalClient (req: express.Request, res: express.Response, next: expr return res.type('json').status(403).end() } - db.OAuthClient.loadFirstClient() - .then(client => { - if (!client) throw new Error('No client available.') - - const json: OAuthClientLocal = { - client_id: client.clientId, - client_secret: client.clientSecret - } - res.json(json) - }) - .catch(err => next(err)) + const client = await db.OAuthClient.loadFirstClient() + if (!client) throw new Error('No client available.') + + const json: OAuthClientLocal = { + client_id: client.clientId, + client_secret: client.clientSecret + } + return res.json(json) } // ---------------------------------------------------------------------------