]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/controllers/api/clients.js
3 const express
= require('express')
4 const mongoose
= require('mongoose')
6 const constants
= require('../../initializers/constants')
8 const Client
= mongoose
.model('OAuthClient')
10 const router
= express
.Router()
12 router
.get('/local', getLocalClient
)
14 // Get the client credentials for the PeerTube front end
15 function getLocalClient (req
, res
, next
) {
16 const serverHostname
= constants
.CONFIG
.WEBSERVER
.HOSTNAME
17 const serverPort
= constants
.CONFIG
.WEBSERVER
.PORT
18 let headerHostShouldBe
= serverHostname
19 if (serverPort
!== 80 && serverPort
!== 443) {
20 headerHostShouldBe
+= ':' + serverPort
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()
28 Client
.loadFirstClient(function (err
, client
) {
29 if (err
) return next(err
)
30 if (!client
) return next(new Error('No client available.'))
33 client_id: client
._id
,
34 client_secret: client
.clientSecret
39 // ---------------------------------------------------------------------------
41 module
.exports
= router