aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/v1/clients.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-08-05 16:09:39 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-08-05 16:09:39 +0200
commit6606150c49f587bc7eb0ecec4263ce7fbb18bf15 (patch)
tree6e0c13983e667e08dcc1dfb6fcda1524b6920c6a /server/controllers/api/v1/clients.js
parent9bd2662976a75d3b03364cdbe6419e57c80f99a6 (diff)
downloadPeerTube-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.js40
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
3const config = require('config')
4const express = require('express')
5const mongoose = require('mongoose')
6
7const Client = mongoose.model('OAuthClient')
8
9const router = express.Router()
10
11router.get('/local', getLocalClient)
12
13// Get the client credentials for the PeerTube front end
14function 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
40module.exports = router