aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/clients.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-10-21 12:16:28 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-10-21 12:16:28 +0200
commitf253b1c1f19d9cb056ab95b2cb6208952e073894 (patch)
treece75f6a96d9ceebd09d33cedfa008c4efb32477b /server/controllers/api/clients.js
parent844e39c2f843c6e2db81699176f13972c29c42fa (diff)
downloadPeerTube-f253b1c1f19d9cb056ab95b2cb6208952e073894.tar.gz
PeerTube-f253b1c1f19d9cb056ab95b2cb6208952e073894.tar.zst
PeerTube-f253b1c1f19d9cb056ab95b2cb6208952e073894.zip
Server: remove v1 directory, we don't really need it
Diffstat (limited to 'server/controllers/api/clients.js')
-rw-r--r--server/controllers/api/clients.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/server/controllers/api/clients.js b/server/controllers/api/clients.js
new file mode 100644
index 000000000..ce1149227
--- /dev/null
+++ b/server/controllers/api/clients.js
@@ -0,0 +1,41 @@
1'use strict'
2
3const express = require('express')
4const mongoose = require('mongoose')
5
6const constants = require('../../initializers/constants')
7
8const Client = mongoose.model('OAuthClient')
9
10const router = express.Router()
11
12router.get('/local', getLocalClient)
13
14// Get the client credentials for the PeerTube front end
15function getLocalClient (req, res, next) {
16 const serverHost = constants.CONFIG.WEBSERVER.HOST
17 const serverPort = constants.CONFIG.WEBSERVER.PORT
18 let headerHostShouldBe = serverHost
19 if (serverPort !== 80 && serverPort !== 443) {
20 headerHostShouldBe += ':' + serverPort
21 }
22
23 // Don't make this check if this is a test instance
24 if (process.env.NODE_ENV !== 'test' && req.get('host') !== headerHostShouldBe) {
25 return res.type('json').status(403).end()
26 }
27
28 Client.loadFirstClient(function (err, client) {
29 if (err) return next(err)
30 if (!client) return next(new Error('No client available.'))
31
32 res.json({
33 client_id: client._id,
34 client_secret: client.clientSecret
35 })
36 })
37}
38
39// ---------------------------------------------------------------------------
40
41module.exports = router