mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-06-18 02:06:25 +00:00
Refactor API Schema and validation
- /schema now returns full openapi/swagger schema - That schema is used to validate incoming requests - And used as a contract in future integration tests - Moved route files up one level - Fixed incorrect 404 reponses when getting objects - Fixed saving new objects and passing jsonschemavalidation
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
const express = require('express');
|
||||
const validator = require('../../lib/validator');
|
||||
const jwtdecode = require('../../lib/express/jwt-decode');
|
||||
const internalAuditLog = require('../../internal/audit-log');
|
||||
const validator = require('../lib/validator');
|
||||
const jwtdecode = require('../lib/express/jwt-decode');
|
||||
const internalAuditLog = require('../internal/audit-log');
|
||||
|
||||
let router = express.Router({
|
||||
caseSensitive: true,
|
||||
@ -14,7 +14,7 @@ let router = express.Router({
|
||||
*/
|
||||
router
|
||||
.route('/')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@ -29,10 +29,10 @@ router
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: 'definitions#/definitions/expand'
|
||||
$ref: 'common#/definitions/expand'
|
||||
},
|
||||
query: {
|
||||
$ref: 'definitions#/definitions/query'
|
||||
$ref: 'common#/definitions/query'
|
||||
}
|
||||
}
|
||||
}, {
|
@ -1,6 +1,6 @@
|
||||
const express = require('express');
|
||||
const pjson = require('../../package.json');
|
||||
const error = require('../../lib/error');
|
||||
const pjson = require('../package.json');
|
||||
const error = require('../lib/error');
|
||||
|
||||
let router = express.Router({
|
||||
caseSensitive: true,
|
||||
@ -43,7 +43,7 @@ router.use('/nginx/certificates', require('./nginx/certificates'));
|
||||
*
|
||||
* ALL /api/*
|
||||
*/
|
||||
router.all(/(.+)/, function (req, res, next) {
|
||||
router.all(/(.+)/, function (req, _, next) {
|
||||
req.params.page = req.params['0'];
|
||||
next(new error.ItemNotFoundError(req.params.page));
|
||||
});
|
@ -1,8 +1,9 @@
|
||||
const express = require('express');
|
||||
const validator = require('../../../lib/validator');
|
||||
const jwtdecode = require('../../../lib/express/jwt-decode');
|
||||
const internalAccessList = require('../../../internal/access-list');
|
||||
const apiValidator = require('../../../lib/validator/api');
|
||||
const validator = require('../../lib/validator');
|
||||
const jwtdecode = require('../../lib/express/jwt-decode');
|
||||
const apiValidator = require('../../lib/validator/api');
|
||||
const internalAccessList = require('../../internal/access-list');
|
||||
const schema = require('../../schema');
|
||||
|
||||
let router = express.Router({
|
||||
caseSensitive: true,
|
||||
@ -30,10 +31,10 @@ router
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: 'definitions#/definitions/expand'
|
||||
$ref: 'common#/definitions/expand'
|
||||
},
|
||||
query: {
|
||||
$ref: 'definitions#/definitions/query'
|
||||
$ref: 'common#/definitions/query'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -56,7 +57,7 @@ router
|
||||
* Create a new access-list
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/access-lists#/links/1/schema'}, req.body)
|
||||
apiValidator(schema.getValidationSchema('/nginx/access-lists', 'post'), req.body)
|
||||
.then((payload) => {
|
||||
return internalAccessList.create(res.locals.access, payload);
|
||||
})
|
||||
@ -74,7 +75,7 @@ router
|
||||
*/
|
||||
router
|
||||
.route('/:list_id')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@ -90,10 +91,10 @@ router
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
list_id: {
|
||||
$ref: 'definitions#/definitions/id'
|
||||
$ref: 'common#/definitions/id'
|
||||
},
|
||||
expand: {
|
||||
$ref: 'definitions#/definitions/expand'
|
||||
$ref: 'common#/definitions/expand'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -119,7 +120,7 @@ router
|
||||
* Update and existing access-list
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/access-lists#/links/2/schema'}, req.body)
|
||||
apiValidator(schema.getValidationSchema('/nginx/access-lists/{listID}', 'put'), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = parseInt(req.params.list_id, 10);
|
||||
return internalAccessList.update(res.locals.access, payload);
|
@ -1,8 +1,10 @@
|
||||
const express = require('express');
|
||||
const validator = require('../../../lib/validator');
|
||||
const jwtdecode = require('../../../lib/express/jwt-decode');
|
||||
const internalCertificate = require('../../../internal/certificate');
|
||||
const apiValidator = require('../../../lib/validator/api');
|
||||
const error = require('../../lib/error');
|
||||
const validator = require('../../lib/validator');
|
||||
const jwtdecode = require('../../lib/express/jwt-decode');
|
||||
const apiValidator = require('../../lib/validator/api');
|
||||
const internalCertificate = require('../../internal/certificate');
|
||||
const schema = require('../../schema');
|
||||
|
||||
let router = express.Router({
|
||||
caseSensitive: true,
|
||||
@ -15,7 +17,7 @@ let router = express.Router({
|
||||
*/
|
||||
router
|
||||
.route('/')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@ -30,10 +32,10 @@ router
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: 'definitions#/definitions/expand'
|
||||
$ref: 'common#/definitions/expand'
|
||||
},
|
||||
query: {
|
||||
$ref: 'definitions#/definitions/query'
|
||||
$ref: 'common#/definitions/query'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -56,7 +58,7 @@ router
|
||||
* Create a new certificate
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/certificates#/links/1/schema'}, req.body)
|
||||
apiValidator(schema.getValidationSchema('/nginx/certificates', 'post'), req.body)
|
||||
.then((payload) => {
|
||||
req.setTimeout(900000); // 15 minutes timeout
|
||||
return internalCertificate.create(res.locals.access, payload);
|
||||
@ -75,17 +77,22 @@ router
|
||||
*/
|
||||
router
|
||||
.route('/test-http')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
|
||||
/**
|
||||
* GET /api/nginx/certificates/test-http
|
||||
*
|
||||
* Test HTTP challenge for domains
|
||||
*/
|
||||
/**
|
||||
* GET /api/nginx/certificates/test-http
|
||||
*
|
||||
* Test HTTP challenge for domains
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
if (req.query.domains === undefined) {
|
||||
next(new error.ValidationError('Domains are required as query parameters'));
|
||||
return;
|
||||
}
|
||||
|
||||
internalCertificate.testHttpsChallenge(res.locals.access, JSON.parse(req.query.domains))
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
@ -101,7 +108,7 @@ router
|
||||
*/
|
||||
router
|
||||
.route('/:certificate_id')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@ -117,10 +124,10 @@ router
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
certificate_id: {
|
||||
$ref: 'definitions#/definitions/id'
|
||||
$ref: 'common#/definitions/id'
|
||||
},
|
||||
expand: {
|
||||
$ref: 'definitions#/definitions/expand'
|
||||
$ref: 'common#/definitions/expand'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -140,24 +147,6 @@ router
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
* PUT /api/nginx/certificates/123
|
||||
*
|
||||
* Update and existing certificate
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/certificates#/links/2/schema'}, req.body)
|
||||
.then((payload) => {
|
||||
payload.id = parseInt(req.params.certificate_id, 10);
|
||||
return internalCertificate.update(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
* DELETE /api/nginx/certificates/123
|
||||
*
|
||||
@ -179,7 +168,7 @@ router
|
||||
*/
|
||||
router
|
||||
.route('/:certificate_id/upload')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@ -213,7 +202,7 @@ router
|
||||
*/
|
||||
router
|
||||
.route('/:certificate_id/renew')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@ -270,7 +259,7 @@ router
|
||||
*/
|
||||
router
|
||||
.route('/validate')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
@ -1,8 +1,9 @@
|
||||
const express = require('express');
|
||||
const validator = require('../../../lib/validator');
|
||||
const jwtdecode = require('../../../lib/express/jwt-decode');
|
||||
const internalDeadHost = require('../../../internal/dead-host');
|
||||
const apiValidator = require('../../../lib/validator/api');
|
||||
const validator = require('../../lib/validator');
|
||||
const jwtdecode = require('../../lib/express/jwt-decode');
|
||||
const apiValidator = require('../../lib/validator/api');
|
||||
const internalDeadHost = require('../../internal/dead-host');
|
||||
const schema = require('../../schema');
|
||||
|
||||
let router = express.Router({
|
||||
caseSensitive: true,
|
||||
@ -15,7 +16,7 @@ let router = express.Router({
|
||||
*/
|
||||
router
|
||||
.route('/')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@ -30,10 +31,10 @@ router
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: 'definitions#/definitions/expand'
|
||||
$ref: 'common#/definitions/expand'
|
||||
},
|
||||
query: {
|
||||
$ref: 'definitions#/definitions/query'
|
||||
$ref: 'common#/definitions/query'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -56,7 +57,7 @@ router
|
||||
* Create a new dead-host
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/dead-hosts#/links/1/schema'}, req.body)
|
||||
apiValidator(schema.getValidationSchema('/nginx/dead-hosts', 'post'), req.body)
|
||||
.then((payload) => {
|
||||
return internalDeadHost.create(res.locals.access, payload);
|
||||
})
|
||||
@ -90,10 +91,10 @@ router
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
host_id: {
|
||||
$ref: 'definitions#/definitions/id'
|
||||
$ref: 'common#/definitions/id'
|
||||
},
|
||||
expand: {
|
||||
$ref: 'definitions#/definitions/expand'
|
||||
$ref: 'common#/definitions/expand'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -119,7 +120,7 @@ router
|
||||
* Update and existing dead-host
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/dead-hosts#/links/2/schema'}, req.body)
|
||||
apiValidator(schema.getValidationSchema('/nginx/dead-hosts/{hostID}', 'put'), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = parseInt(req.params.host_id, 10);
|
||||
return internalDeadHost.update(res.locals.access, payload);
|
||||
@ -152,7 +153,7 @@ router
|
||||
*/
|
||||
router
|
||||
.route('/:host_id/enable')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@ -176,7 +177,7 @@ router
|
||||
*/
|
||||
router
|
||||
.route('/:host_id/disable')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
@ -1,8 +1,9 @@
|
||||
const express = require('express');
|
||||
const validator = require('../../../lib/validator');
|
||||
const jwtdecode = require('../../../lib/express/jwt-decode');
|
||||
const internalProxyHost = require('../../../internal/proxy-host');
|
||||
const apiValidator = require('../../../lib/validator/api');
|
||||
const validator = require('../../lib/validator');
|
||||
const jwtdecode = require('../../lib/express/jwt-decode');
|
||||
const apiValidator = require('../../lib/validator/api');
|
||||
const internalProxyHost = require('../../internal/proxy-host');
|
||||
const schema = require('../../schema');
|
||||
|
||||
let router = express.Router({
|
||||
caseSensitive: true,
|
||||
@ -30,10 +31,10 @@ router
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: 'definitions#/definitions/expand'
|
||||
$ref: 'common#/definitions/expand'
|
||||
},
|
||||
query: {
|
||||
$ref: 'definitions#/definitions/query'
|
||||
$ref: 'common#/definitions/query'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -56,7 +57,7 @@ router
|
||||
* Create a new proxy-host
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/proxy-hosts#/links/1/schema'}, req.body)
|
||||
apiValidator(schema.getValidationSchema('/nginx/proxy-hosts', 'post'), req.body)
|
||||
.then((payload) => {
|
||||
return internalProxyHost.create(res.locals.access, payload);
|
||||
})
|
||||
@ -90,10 +91,10 @@ router
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
host_id: {
|
||||
$ref: 'definitions#/definitions/id'
|
||||
$ref: 'common#/definitions/id'
|
||||
},
|
||||
expand: {
|
||||
$ref: 'definitions#/definitions/expand'
|
||||
$ref: 'common#/definitions/expand'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -119,7 +120,7 @@ router
|
||||
* Update and existing proxy-host
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/proxy-hosts#/links/2/schema'}, req.body)
|
||||
apiValidator(schema.getValidationSchema('/nginx/proxy-hosts/{hostID}', 'put'), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = parseInt(req.params.host_id, 10);
|
||||
return internalProxyHost.update(res.locals.access, payload);
|
||||
@ -152,7 +153,7 @@ router
|
||||
*/
|
||||
router
|
||||
.route('/:host_id/enable')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@ -176,7 +177,7 @@ router
|
||||
*/
|
||||
router
|
||||
.route('/:host_id/disable')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
@ -1,8 +1,9 @@
|
||||
const express = require('express');
|
||||
const validator = require('../../../lib/validator');
|
||||
const jwtdecode = require('../../../lib/express/jwt-decode');
|
||||
const internalRedirectionHost = require('../../../internal/redirection-host');
|
||||
const apiValidator = require('../../../lib/validator/api');
|
||||
const validator = require('../../lib/validator');
|
||||
const jwtdecode = require('../../lib/express/jwt-decode');
|
||||
const apiValidator = require('../../lib/validator/api');
|
||||
const internalRedirectionHost = require('../../internal/redirection-host');
|
||||
const schema = require('../../schema');
|
||||
|
||||
let router = express.Router({
|
||||
caseSensitive: true,
|
||||
@ -30,10 +31,10 @@ router
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: 'definitions#/definitions/expand'
|
||||
$ref: 'common#/definitions/expand'
|
||||
},
|
||||
query: {
|
||||
$ref: 'definitions#/definitions/query'
|
||||
$ref: 'common#/definitions/query'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -56,7 +57,7 @@ router
|
||||
* Create a new redirection-host
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/redirection-hosts#/links/1/schema'}, req.body)
|
||||
apiValidator(schema.getValidationSchema('/nginx/redirection-hosts', 'post'), req.body)
|
||||
.then((payload) => {
|
||||
return internalRedirectionHost.create(res.locals.access, payload);
|
||||
})
|
||||
@ -90,10 +91,10 @@ router
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
host_id: {
|
||||
$ref: 'definitions#/definitions/id'
|
||||
$ref: 'common#/definitions/id'
|
||||
},
|
||||
expand: {
|
||||
$ref: 'definitions#/definitions/expand'
|
||||
$ref: 'common#/definitions/expand'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -119,7 +120,7 @@ router
|
||||
* Update and existing redirection-host
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/redirection-hosts#/links/2/schema'}, req.body)
|
||||
apiValidator(schema.getValidationSchema('/nginx/redirection-hosts/{hostID}', 'put'), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = parseInt(req.params.host_id, 10);
|
||||
return internalRedirectionHost.update(res.locals.access, payload);
|
@ -1,8 +1,9 @@
|
||||
const express = require('express');
|
||||
const validator = require('../../../lib/validator');
|
||||
const jwtdecode = require('../../../lib/express/jwt-decode');
|
||||
const internalStream = require('../../../internal/stream');
|
||||
const apiValidator = require('../../../lib/validator/api');
|
||||
const validator = require('../../lib/validator');
|
||||
const jwtdecode = require('../../lib/express/jwt-decode');
|
||||
const apiValidator = require('../../lib/validator/api');
|
||||
const internalStream = require('../../internal/stream');
|
||||
const schema = require('../../schema');
|
||||
|
||||
let router = express.Router({
|
||||
caseSensitive: true,
|
||||
@ -30,10 +31,10 @@ router
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: 'definitions#/definitions/expand'
|
||||
$ref: 'common#/definitions/expand'
|
||||
},
|
||||
query: {
|
||||
$ref: 'definitions#/definitions/query'
|
||||
$ref: 'common#/definitions/query'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -56,7 +57,7 @@ router
|
||||
* Create a new stream
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/streams#/links/1/schema'}, req.body)
|
||||
apiValidator(schema.getValidationSchema('/nginx/streams', 'post'), req.body)
|
||||
.then((payload) => {
|
||||
return internalStream.create(res.locals.access, payload);
|
||||
})
|
||||
@ -90,10 +91,10 @@ router
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
stream_id: {
|
||||
$ref: 'definitions#/definitions/id'
|
||||
$ref: 'common#/definitions/id'
|
||||
},
|
||||
expand: {
|
||||
$ref: 'definitions#/definitions/expand'
|
||||
$ref: 'common#/definitions/expand'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -119,7 +120,7 @@ router
|
||||
* Update and existing stream
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/streams#/links/2/schema'}, req.body)
|
||||
apiValidator(schema.getValidationSchema('/nginx/streams/{streamID}', 'put'), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = parseInt(req.params.stream_id, 10);
|
||||
return internalStream.update(res.locals.access, payload);
|
||||
@ -152,7 +153,7 @@ router
|
||||
*/
|
||||
router
|
||||
.route('/:host_id/enable')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@ -176,7 +177,7 @@ router
|
||||
*/
|
||||
router
|
||||
.route('/:host_id/disable')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
@ -1,6 +1,6 @@
|
||||
const express = require('express');
|
||||
const jwtdecode = require('../../lib/express/jwt-decode');
|
||||
const internalReport = require('../../internal/report');
|
||||
const jwtdecode = require('../lib/express/jwt-decode');
|
||||
const internalReport = require('../internal/report');
|
||||
|
||||
let router = express.Router({
|
||||
caseSensitive: true,
|
||||
@ -10,14 +10,14 @@ let router = express.Router({
|
||||
|
||||
router
|
||||
.route('/hosts')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
|
||||
/**
|
||||
* GET /reports/hosts
|
||||
*/
|
||||
.get(jwtdecode(), (req, res, next) => {
|
||||
.get(jwtdecode(), (_, res, next) => {
|
||||
internalReport.getHostsReport(res.locals.access)
|
||||
.then((data) => {
|
||||
res.status(200)
|
@ -1,8 +1,8 @@
|
||||
const express = require('express');
|
||||
const swaggerJSON = require('../../doc/api.swagger.json');
|
||||
const PACKAGE = require('../../package.json');
|
||||
const express = require('express');
|
||||
const schema = require('../schema');
|
||||
const PACKAGE = require('../package.json');
|
||||
|
||||
let router = express.Router({
|
||||
const router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
@ -10,14 +10,16 @@ let router = express.Router({
|
||||
|
||||
router
|
||||
.route('/')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
|
||||
/**
|
||||
* GET /schema
|
||||
*/
|
||||
.get((req, res/*, next*/) => {
|
||||
.get(async (req, res) => {
|
||||
let swaggerJSON = await schema.getCompiledSchema();
|
||||
|
||||
let proto = req.protocol;
|
||||
if (typeof req.headers['x-forwarded-proto'] !== 'undefined' && req.headers['x-forwarded-proto']) {
|
||||
proto = req.headers['x-forwarded-proto'];
|
@ -1,8 +1,9 @@
|
||||
const express = require('express');
|
||||
const validator = require('../../lib/validator');
|
||||
const jwtdecode = require('../../lib/express/jwt-decode');
|
||||
const internalSetting = require('../../internal/setting');
|
||||
const apiValidator = require('../../lib/validator/api');
|
||||
const validator = require('../lib/validator');
|
||||
const jwtdecode = require('../lib/express/jwt-decode');
|
||||
const apiValidator = require('../lib/validator/api');
|
||||
const internalSetting = require('../internal/setting');
|
||||
const schema = require('../schema');
|
||||
|
||||
let router = express.Router({
|
||||
caseSensitive: true,
|
||||
@ -15,7 +16,7 @@ let router = express.Router({
|
||||
*/
|
||||
router
|
||||
.route('/')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@ -25,7 +26,7 @@ router
|
||||
*
|
||||
* Retrieve all settings
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
.get((_, res, next) => {
|
||||
internalSetting.getAll(res.locals.access)
|
||||
.then((rows) => {
|
||||
res.status(200)
|
||||
@ -41,7 +42,7 @@ router
|
||||
*/
|
||||
router
|
||||
.route('/:setting_id')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@ -57,7 +58,8 @@ router
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
setting_id: {
|
||||
$ref: 'definitions#/definitions/setting_id'
|
||||
type: 'string',
|
||||
minLength: 1
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -81,7 +83,7 @@ router
|
||||
* Update and existing setting
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/settings#/links/1/schema'}, req.body)
|
||||
apiValidator(schema.getValidationSchema('/settings/{settingID}', 'put'), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = req.params.setting_id;
|
||||
return internalSetting.update(res.locals.access, payload);
|
@ -1,7 +1,8 @@
|
||||
const express = require('express');
|
||||
const jwtdecode = require('../../lib/express/jwt-decode');
|
||||
const internalToken = require('../../internal/token');
|
||||
const apiValidator = require('../../lib/validator/api');
|
||||
const jwtdecode = require('../lib/express/jwt-decode');
|
||||
const apiValidator = require('../lib/validator/api');
|
||||
const internalToken = require('../internal/token');
|
||||
const schema = require('../schema');
|
||||
|
||||
let router = express.Router({
|
||||
caseSensitive: true,
|
||||
@ -11,7 +12,7 @@ let router = express.Router({
|
||||
|
||||
router
|
||||
.route('/')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
|
||||
@ -39,11 +40,9 @@ router
|
||||
*
|
||||
* Create a new Token
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/tokens#/links/0/schema'}, req.body)
|
||||
.then((payload) => {
|
||||
return internalToken.getTokenFromEmail(payload);
|
||||
})
|
||||
.post(async (req, res, next) => {
|
||||
apiValidator(schema.getValidationSchema('/tokens', 'post'), req.body)
|
||||
.then(internalToken.getTokenFromEmail)
|
||||
.then((data) => {
|
||||
res.status(200)
|
||||
.send(data);
|
@ -1,9 +1,10 @@
|
||||
const express = require('express');
|
||||
const validator = require('../../lib/validator');
|
||||
const jwtdecode = require('../../lib/express/jwt-decode');
|
||||
const userIdFromMe = require('../../lib/express/user-id-from-me');
|
||||
const internalUser = require('../../internal/user');
|
||||
const apiValidator = require('../../lib/validator/api');
|
||||
const validator = require('../lib/validator');
|
||||
const jwtdecode = require('../lib/express/jwt-decode');
|
||||
const userIdFromMe = require('../lib/express/user-id-from-me');
|
||||
const internalUser = require('../internal/user');
|
||||
const apiValidator = require('../lib/validator/api');
|
||||
const schema = require('../schema');
|
||||
|
||||
let router = express.Router({
|
||||
caseSensitive: true,
|
||||
@ -16,7 +17,7 @@ let router = express.Router({
|
||||
*/
|
||||
router
|
||||
.route('/')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@ -31,10 +32,10 @@ router
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: 'definitions#/definitions/expand'
|
||||
$ref: 'common#/definitions/expand'
|
||||
},
|
||||
query: {
|
||||
$ref: 'definitions#/definitions/query'
|
||||
$ref: 'common#/definitions/query'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -48,7 +49,11 @@ router
|
||||
res.status(200)
|
||||
.send(users);
|
||||
})
|
||||
.catch(next);
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
next(err);
|
||||
});
|
||||
//.catch(next);
|
||||
})
|
||||
|
||||
/**
|
||||
@ -57,7 +62,7 @@ router
|
||||
* Create a new User
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/users#/links/1/schema'}, req.body)
|
||||
apiValidator(schema.getValidationSchema('/users', 'post'), req.body)
|
||||
.then((payload) => {
|
||||
return internalUser.create(res.locals.access, payload);
|
||||
})
|
||||
@ -75,7 +80,7 @@ router
|
||||
*/
|
||||
router
|
||||
.route('/:user_id')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@ -92,10 +97,10 @@ router
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
user_id: {
|
||||
$ref: 'definitions#/definitions/id'
|
||||
$ref: 'common#/definitions/id'
|
||||
},
|
||||
expand: {
|
||||
$ref: 'definitions#/definitions/expand'
|
||||
$ref: 'common#/definitions/expand'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -113,7 +118,10 @@ router
|
||||
res.status(200)
|
||||
.send(user);
|
||||
})
|
||||
.catch(next);
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
next(err);
|
||||
});
|
||||
})
|
||||
|
||||
/**
|
||||
@ -122,7 +130,7 @@ router
|
||||
* Update and existing user
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/users#/links/2/schema'}, req.body)
|
||||
apiValidator(schema.getValidationSchema('/users/{userID}', 'put'), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = req.params.user_id;
|
||||
return internalUser.update(res.locals.access, payload);
|
||||
@ -167,7 +175,7 @@ router
|
||||
* Update password for a user
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/users#/links/4/schema'}, req.body)
|
||||
apiValidator(schema.getValidationSchema('/users/{userID}/auth', 'put'), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = req.params.user_id;
|
||||
return internalUser.setPassword(res.locals.access, payload);
|
||||
@ -198,7 +206,7 @@ router
|
||||
* Set some or all permissions for a user
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator({$ref: 'endpoints/users#/links/5/schema'}, req.body)
|
||||
apiValidator(schema.getValidationSchema('/users/{userID}/permissions', 'put'), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = req.params.user_id;
|
||||
return internalUser.setPermissions(res.locals.access, payload);
|
||||
@ -217,7 +225,7 @@ router
|
||||
*/
|
||||
router
|
||||
.route('/:user_id/login')
|
||||
.options((req, res) => {
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
Reference in New Issue
Block a user