From 0a381679e04bc7adf097da9a6fb4e2c8f41bbda2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 25 Jun 2017 17:44:19 +0200 Subject: ClientLocal -> OAuthClientLocal --- server/controllers/api/clients.ts | 43 --------------------------------- server/controllers/api/index.ts | 4 +-- server/controllers/api/oauth-clients.ts | 43 +++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 45 deletions(-) delete mode 100644 server/controllers/api/clients.ts create mode 100644 server/controllers/api/oauth-clients.ts (limited to 'server/controllers/api') diff --git a/server/controllers/api/clients.ts b/server/controllers/api/clients.ts deleted file mode 100644 index 96490d04a..000000000 --- a/server/controllers/api/clients.ts +++ /dev/null @@ -1,43 +0,0 @@ -import * as express from 'express' - -import { CONFIG } from '../../initializers' -import { logger } from '../../helpers' -import { database as db } from '../../initializers/database' -import { ClientLocal } from '../../../shared' - -const clientsRouter = express.Router() - -clientsRouter.get('/local', getLocalClient) - -// Get the client credentials for the PeerTube front end -function getLocalClient (req: express.Request, res: express.Response, next: express.NextFunction) { - const serverHostname = CONFIG.WEBSERVER.HOSTNAME - const serverPort = CONFIG.WEBSERVER.PORT - let headerHostShouldBe = serverHostname - if (serverPort !== 80 && serverPort !== 443) { - headerHostShouldBe += ':' + serverPort - } - - // Don't make this check if this is a test instance - if (process.env.NODE_ENV !== 'test' && req.get('host') !== headerHostShouldBe) { - logger.info('Getting client tokens for host %s is forbidden (expected %s).', req.get('host'), headerHostShouldBe) - return res.type('json').status(403).end() - } - - db.OAuthClient.loadFirstClient(function (err, client) { - if (err) return next(err) - if (!client) return next(new Error('No client available.')) - - const json: ClientLocal = { - client_id: client.clientId, - client_secret: client.clientSecret - } - res.json(json) - }) -} - -// --------------------------------------------------------------------------- - -export { - clientsRouter -} diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts index 3abe9bcf8..a9205b33c 100644 --- a/server/controllers/api/index.ts +++ b/server/controllers/api/index.ts @@ -2,7 +2,7 @@ import * as express from 'express' import { badRequest } from '../../helpers' -import { clientsRouter } from './clients' +import { oauthClientsRouter } from './oauth-clients' import { configRouter } from './config' import { podsRouter } from './pods' import { remoteRouter } from './remote' @@ -12,7 +12,7 @@ import { videosRouter } from './videos' const apiRouter = express.Router() -apiRouter.use('/clients', clientsRouter) +apiRouter.use('/oauth-clients', oauthClientsRouter) apiRouter.use('/config', configRouter) apiRouter.use('/pods', podsRouter) apiRouter.use('/remote', remoteRouter) diff --git a/server/controllers/api/oauth-clients.ts b/server/controllers/api/oauth-clients.ts new file mode 100644 index 000000000..b9bc0534f --- /dev/null +++ b/server/controllers/api/oauth-clients.ts @@ -0,0 +1,43 @@ +import * as express from 'express' + +import { CONFIG } from '../../initializers' +import { logger } from '../../helpers' +import { database as db } from '../../initializers/database' +import { OAuthClientLocal } from '../../../shared' + +const oauthClientsRouter = express.Router() + +oauthClientsRouter.get('/local', getLocalClient) + +// Get the client credentials for the PeerTube front end +function getLocalClient (req: express.Request, res: express.Response, next: express.NextFunction) { + const serverHostname = CONFIG.WEBSERVER.HOSTNAME + const serverPort = CONFIG.WEBSERVER.PORT + let headerHostShouldBe = serverHostname + if (serverPort !== 80 && serverPort !== 443) { + headerHostShouldBe += ':' + serverPort + } + + // Don't make this check if this is a test instance + if (process.env.NODE_ENV !== 'test' && req.get('host') !== headerHostShouldBe) { + logger.info('Getting client tokens for host %s is forbidden (expected %s).', req.get('host'), headerHostShouldBe) + return res.type('json').status(403).end() + } + + db.OAuthClient.loadFirstClient(function (err, client) { + if (err) return next(err) + if (!client) return next(new Error('No client available.')) + + const json: OAuthClientLocal = { + client_id: client.clientId, + client_secret: client.clientSecret + } + res.json(json) + }) +} + +// --------------------------------------------------------------------------- + +export { + oauthClientsRouter +} -- cgit v1.2.3