Server: move remote routes in their own directory
This commit is contained in:
parent
8fd66b75bf
commit
a6fd2b30bf
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
|
|
||||||
|
const utils = require('../../helpers/utils')
|
||||||
|
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
const clientsController = require('./clients')
|
const clientsController = require('./clients')
|
||||||
|
@ -18,7 +20,7 @@ router.use('/requests', requestsController)
|
||||||
router.use('/users', usersController)
|
router.use('/users', usersController)
|
||||||
router.use('/videos', videosController)
|
router.use('/videos', videosController)
|
||||||
router.use('/ping', pong)
|
router.use('/ping', pong)
|
||||||
router.use('/*', badRequest)
|
router.use('/*', utils.badRequest)
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -29,7 +31,3 @@ module.exports = router
|
||||||
function pong (req, res, next) {
|
function pong (req, res, next) {
|
||||||
return res.send('pong').status(200).end()
|
return res.send('pong').status(200).end()
|
||||||
}
|
}
|
||||||
|
|
||||||
function badRequest (req, res, next) {
|
|
||||||
res.type('json').status(400).end()
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const express = require('express')
|
||||||
|
|
||||||
|
const utils = require('../../../helpers/utils')
|
||||||
|
|
||||||
|
const router = express.Router()
|
||||||
|
|
||||||
|
const videosRemoteController = require('./videos')
|
||||||
|
|
||||||
|
router.use('/videos', videosRemoteController)
|
||||||
|
router.use('/*', utils.badRequest)
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
module.exports = router
|
|
@ -4,15 +4,15 @@ const eachSeries = require('async/eachSeries')
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const waterfall = require('async/waterfall')
|
const waterfall = require('async/waterfall')
|
||||||
|
|
||||||
const db = require('../../initializers/database')
|
const db = require('../../../initializers/database')
|
||||||
const middlewares = require('../../middlewares')
|
const middlewares = require('../../../middlewares')
|
||||||
const secureMiddleware = middlewares.secure
|
const secureMiddleware = middlewares.secure
|
||||||
const validators = middlewares.validators.remote
|
const validators = middlewares.validators.remote
|
||||||
const logger = require('../../helpers/logger')
|
const logger = require('../../../helpers/logger')
|
||||||
|
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
router.post('/videos',
|
router.post('/',
|
||||||
validators.signature,
|
validators.signature,
|
||||||
secureMiddleware.checkSignature,
|
secureMiddleware.checkSignature,
|
||||||
validators.remoteVideos,
|
validators.remoteVideos,
|
|
@ -5,11 +5,16 @@ const crypto = require('crypto')
|
||||||
const logger = require('./logger')
|
const logger = require('./logger')
|
||||||
|
|
||||||
const utils = {
|
const utils = {
|
||||||
|
badRequest,
|
||||||
cleanForExit,
|
cleanForExit,
|
||||||
generateRandomString,
|
generateRandomString,
|
||||||
isTestInstance
|
isTestInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function badRequest (req, res, next) {
|
||||||
|
res.type('json').status(400).end()
|
||||||
|
}
|
||||||
|
|
||||||
function generateRandomString (size, callback) {
|
function generateRandomString (size, callback) {
|
||||||
crypto.pseudoRandomBytes(size, function (err, raw) {
|
crypto.pseudoRandomBytes(size, function (err, raw) {
|
||||||
if (err) return callback(err)
|
if (err) return callback(err)
|
||||||
|
|
Loading…
Reference in New Issue