diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-08-05 16:09:39 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-08-05 16:09:39 +0200 |
commit | 6606150c49f587bc7eb0ecec4263ce7fbb18bf15 (patch) | |
tree | 6e0c13983e667e08dcc1dfb6fcda1524b6920c6a /server/controllers/api/v1/clients.js | |
parent | 9bd2662976a75d3b03364cdbe6419e57c80f99a6 (diff) | |
download | PeerTube-6606150c49f587bc7eb0ecec4263ce7fbb18bf15.tar.gz PeerTube-6606150c49f587bc7eb0ecec4263ce7fbb18bf15.tar.zst PeerTube-6606150c49f587bc7eb0ecec4263ce7fbb18bf15.zip |
Server: move clients in its own file
Diffstat (limited to 'server/controllers/api/v1/clients.js')
-rw-r--r-- | server/controllers/api/v1/clients.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/server/controllers/api/v1/clients.js b/server/controllers/api/v1/clients.js new file mode 100644 index 000000000..0d222634b --- /dev/null +++ b/server/controllers/api/v1/clients.js | |||
@@ -0,0 +1,40 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const config = require('config') | ||
4 | const express = require('express') | ||
5 | const mongoose = require('mongoose') | ||
6 | |||
7 | const Client = mongoose.model('OAuthClient') | ||
8 | |||
9 | const router = express.Router() | ||
10 | |||
11 | router.get('/local', getLocalClient) | ||
12 | |||
13 | // Get the client credentials for the PeerTube front end | ||
14 | function getLocalClient (req, res, next) { | ||
15 | const serverHost = config.get('webserver.host') | ||
16 | const serverPort = config.get('webserver.port') | ||
17 | let headerHostShouldBe = serverHost | ||
18 | if (serverPort !== 80 && serverPort !== 443) { | ||
19 | headerHostShouldBe += ':' + serverPort | ||
20 | } | ||
21 | |||
22 | // Don't make this check if this is a test instance | ||
23 | if (process.env.NODE_ENV !== 'test' && req.get('host') !== headerHostShouldBe) { | ||
24 | return res.type('json').status(403).end() | ||
25 | } | ||
26 | |||
27 | Client.loadFirstClient(function (err, client) { | ||
28 | if (err) return next(err) | ||
29 | if (!client) return next(new Error('No client available.')) | ||
30 | |||
31 | res.json({ | ||
32 | client_id: client._id, | ||
33 | client_secret: client.clientSecret | ||
34 | }) | ||
35 | }) | ||
36 | } | ||
37 | |||
38 | // --------------------------------------------------------------------------- | ||
39 | |||
40 | module.exports = router | ||