mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-09-14 10:52:34 +00:00
Convert backend to ESM
- About 5 years overdue - Remove eslint, use bomejs instead
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
const express = require('express');
|
||||
const validator = require('../lib/validator');
|
||||
const jwtdecode = require('../lib/express/jwt-decode');
|
||||
const internalAuditLog = require('../internal/audit-log');
|
||||
import express from "express";
|
||||
import internalAuditLog from "../internal/audit-log.js";
|
||||
import jwtdecode from "../lib/express/jwt-decode.js";
|
||||
import validator from "../lib/validator/index.js";
|
||||
|
||||
let router = express.Router({
|
||||
const router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
strict: true,
|
||||
mergeParams: true,
|
||||
});
|
||||
|
||||
/**
|
||||
* /api/audit-log
|
||||
*/
|
||||
router
|
||||
.route('/')
|
||||
.route("/")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -25,28 +25,30 @@ router
|
||||
* Retrieve all logs
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
validator({
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: 'common#/properties/expand'
|
||||
validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
},
|
||||
query: {
|
||||
$ref: 'common#/properties/query'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null),
|
||||
query: (typeof req.query.query === 'string' ? req.query.query : null)
|
||||
})
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalAuditLog.getAll(res.locals.access, data.expand, data.query);
|
||||
})
|
||||
.then((rows) => {
|
||||
res.status(200)
|
||||
.send(rows);
|
||||
res.status(200).send(rows);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
export default router;
|
||||
|
@@ -1,51 +1,63 @@
|
||||
const express = require('express');
|
||||
const pjson = require('../package.json');
|
||||
const error = require('../lib/error');
|
||||
import express from "express";
|
||||
import errs from "../lib/error.js";
|
||||
import pjson from "../package.json" with { type: "json" };
|
||||
import auditLogRoutes from "./audit-log.js";
|
||||
import accessListsRoutes from "./nginx/access_lists.js";
|
||||
import certificatesHostsRoutes from "./nginx/certificates.js";
|
||||
import deadHostsRoutes from "./nginx/dead_hosts.js";
|
||||
import proxyHostsRoutes from "./nginx/proxy_hosts.js";
|
||||
import redirectionHostsRoutes from "./nginx/redirection_hosts.js";
|
||||
import streamsRoutes from "./nginx/streams.js";
|
||||
import reportsRoutes from "./reports.js";
|
||||
import schemaRoutes from "./schema.js";
|
||||
import settingsRoutes from "./settings.js";
|
||||
import tokensRoutes from "./tokens.js";
|
||||
import usersRoutes from "./users.js";
|
||||
|
||||
let router = express.Router({
|
||||
const router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
strict: true,
|
||||
mergeParams: true,
|
||||
});
|
||||
|
||||
/**
|
||||
* Health Check
|
||||
* GET /api
|
||||
*/
|
||||
router.get('/', (req, res/*, next*/) => {
|
||||
let version = pjson.version.split('-').shift().split('.');
|
||||
router.get("/", (_, res /*, next*/) => {
|
||||
const version = pjson.version.split("-").shift().split(".");
|
||||
|
||||
res.status(200).send({
|
||||
status: 'OK',
|
||||
status: "OK",
|
||||
version: {
|
||||
major: parseInt(version.shift(), 10),
|
||||
minor: parseInt(version.shift(), 10),
|
||||
revision: parseInt(version.shift(), 10)
|
||||
}
|
||||
major: Number.parseInt(version.shift(), 10),
|
||||
minor: Number.parseInt(version.shift(), 10),
|
||||
revision: Number.parseInt(version.shift(), 10),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
router.use('/schema', require('./schema'));
|
||||
router.use('/tokens', require('./tokens'));
|
||||
router.use('/users', require('./users'));
|
||||
router.use('/audit-log', require('./audit-log'));
|
||||
router.use('/reports', require('./reports'));
|
||||
router.use('/settings', require('./settings'));
|
||||
router.use('/nginx/proxy-hosts', require('./nginx/proxy_hosts'));
|
||||
router.use('/nginx/redirection-hosts', require('./nginx/redirection_hosts'));
|
||||
router.use('/nginx/dead-hosts', require('./nginx/dead_hosts'));
|
||||
router.use('/nginx/streams', require('./nginx/streams'));
|
||||
router.use('/nginx/access-lists', require('./nginx/access_lists'));
|
||||
router.use('/nginx/certificates', require('./nginx/certificates'));
|
||||
router.use("/schema", schemaRoutes);
|
||||
router.use("/tokens", tokensRoutes);
|
||||
router.use("/users", usersRoutes);
|
||||
router.use("/audit-log", auditLogRoutes);
|
||||
router.use("/reports", reportsRoutes);
|
||||
router.use("/settings", settingsRoutes);
|
||||
router.use("/nginx/proxy-hosts", proxyHostsRoutes);
|
||||
router.use("/nginx/redirection-hosts", redirectionHostsRoutes);
|
||||
router.use("/nginx/dead-hosts", deadHostsRoutes);
|
||||
router.use("/nginx/streams", streamsRoutes);
|
||||
router.use("/nginx/access-lists", accessListsRoutes);
|
||||
router.use("/nginx/certificates", certificatesHostsRoutes);
|
||||
|
||||
/**
|
||||
* API 404 for all other routes
|
||||
*
|
||||
* ALL /api/*
|
||||
*/
|
||||
router.all(/(.+)/, function (req, _, next) {
|
||||
req.params.page = req.params['0'];
|
||||
next(new error.ItemNotFoundError(req.params.page));
|
||||
router.all(/(.+)/, (req, _, next) => {
|
||||
req.params.page = req.params["0"];
|
||||
next(new errs.ItemNotFoundError(req.params.page));
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
export default router;
|
||||
|
@@ -1,22 +1,22 @@
|
||||
const express = require('express');
|
||||
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');
|
||||
import express from "express";
|
||||
import internalAccessList from "../../internal/access-list.js";
|
||||
import jwtdecode from "../../lib/express/jwt-decode.js";
|
||||
import apiValidator from "../../lib/validator/api.js";
|
||||
import validator from "../../lib/validator/index.js";
|
||||
import { getValidationSchema } from "../../schema/index.js";
|
||||
|
||||
let router = express.Router({
|
||||
const router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
strict: true,
|
||||
mergeParams: true,
|
||||
});
|
||||
|
||||
/**
|
||||
* /api/nginx/access-lists
|
||||
*/
|
||||
router
|
||||
.route('/')
|
||||
.options((req, res) => {
|
||||
.route("/")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@@ -27,26 +27,28 @@ router
|
||||
* Retrieve all access-lists
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
validator({
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: 'common#/properties/expand'
|
||||
validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
},
|
||||
query: {
|
||||
$ref: 'common#/properties/query'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null),
|
||||
query: (typeof req.query.query === 'string' ? req.query.query : null)
|
||||
})
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalAccessList.getAll(res.locals.access, data.expand, data.query);
|
||||
})
|
||||
.then((rows) => {
|
||||
res.status(200)
|
||||
.send(rows);
|
||||
res.status(200).send(rows);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -57,13 +59,12 @@ router
|
||||
* Create a new access-list
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
apiValidator(schema.getValidationSchema('/nginx/access-lists', 'post'), req.body)
|
||||
apiValidator(getValidationSchema("/nginx/access-lists", "post"), req.body)
|
||||
.then((payload) => {
|
||||
return internalAccessList.create(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(201)
|
||||
.send(result);
|
||||
res.status(201).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -74,7 +75,7 @@ router
|
||||
* /api/nginx/access-lists/123
|
||||
*/
|
||||
router
|
||||
.route('/:list_id')
|
||||
.route("/:list_id")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -86,30 +87,32 @@ router
|
||||
* Retrieve a specific access-list
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
validator({
|
||||
required: ['list_id'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
list_id: {
|
||||
$ref: 'common#/properties/id'
|
||||
validator(
|
||||
{
|
||||
required: ["list_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
list_id: {
|
||||
$ref: "common#/properties/id",
|
||||
},
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
},
|
||||
expand: {
|
||||
$ref: 'common#/properties/expand'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
list_id: req.params.list_id,
|
||||
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null)
|
||||
})
|
||||
},
|
||||
{
|
||||
list_id: req.params.list_id,
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalAccessList.get(res.locals.access, {
|
||||
id: parseInt(data.list_id, 10),
|
||||
expand: data.expand
|
||||
id: Number.parseInt(data.list_id, 10),
|
||||
expand: data.expand,
|
||||
});
|
||||
})
|
||||
.then((row) => {
|
||||
res.status(200)
|
||||
.send(row);
|
||||
res.status(200).send(row);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -120,14 +123,13 @@ router
|
||||
* Update and existing access-list
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator(schema.getValidationSchema('/nginx/access-lists/{listID}', 'put'), req.body)
|
||||
apiValidator(getValidationSchema("/nginx/access-lists/{listID}", "put"), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = parseInt(req.params.list_id, 10);
|
||||
payload.id = Number.parseInt(req.params.list_id, 10);
|
||||
return internalAccessList.update(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -138,12 +140,12 @@ router
|
||||
* Delete and existing access-list
|
||||
*/
|
||||
.delete((req, res, next) => {
|
||||
internalAccessList.delete(res.locals.access, {id: parseInt(req.params.list_id, 10)})
|
||||
internalAccessList
|
||||
.delete(res.locals.access, { id: Number.parseInt(req.params.list_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
export default router;
|
||||
|
@@ -1,22 +1,22 @@
|
||||
const express = require('express');
|
||||
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');
|
||||
import express from "express";
|
||||
import internalCertificate from "../../internal/certificate.js";
|
||||
import errs from "../../lib/error.js";
|
||||
import jwtdecode from "../../lib/express/jwt-decode.js";
|
||||
import apiValidator from "../../lib/validator/api.js";
|
||||
import validator from "../../lib/validator/index.js";
|
||||
import { getValidationSchema } from "../../schema/index.js";
|
||||
|
||||
const router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
strict: true,
|
||||
mergeParams: true,
|
||||
});
|
||||
|
||||
/**
|
||||
* /api/nginx/certificates
|
||||
*/
|
||||
router
|
||||
.route('/')
|
||||
.route("/")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -28,26 +28,28 @@ router
|
||||
* Retrieve all certificates
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
validator({
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: 'common#/properties/expand'
|
||||
validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
},
|
||||
query: {
|
||||
$ref: 'common#/properties/query'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null),
|
||||
query: (typeof req.query.query === 'string' ? req.query.query : null)
|
||||
})
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalCertificate.getAll(res.locals.access, data.expand, data.query);
|
||||
})
|
||||
.then((rows) => {
|
||||
res.status(200)
|
||||
.send(rows);
|
||||
res.status(200).send(rows);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -58,14 +60,13 @@ router
|
||||
* Create a new certificate
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
apiValidator(schema.getValidationSchema('/nginx/certificates', 'post'), req.body)
|
||||
apiValidator(getValidationSchema("/nginx/certificates", "post"), req.body)
|
||||
.then((payload) => {
|
||||
req.setTimeout(900000); // 15 minutes timeout
|
||||
return internalCertificate.create(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(201)
|
||||
.send(result);
|
||||
res.status(201).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -76,7 +77,7 @@ router
|
||||
* /api/nginx/certificates/test-http
|
||||
*/
|
||||
router
|
||||
.route('/test-http')
|
||||
.route("/test-http")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -89,14 +90,14 @@ router
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
if (req.query.domains === undefined) {
|
||||
next(new error.ValidationError('Domains are required as query parameters'));
|
||||
next(new errs.ValidationError("Domains are required as query parameters"));
|
||||
return;
|
||||
}
|
||||
|
||||
internalCertificate.testHttpsChallenge(res.locals.access, JSON.parse(req.query.domains))
|
||||
internalCertificate
|
||||
.testHttpsChallenge(res.locals.access, JSON.parse(req.query.domains))
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -107,7 +108,7 @@ router
|
||||
* /api/nginx/certificates/123
|
||||
*/
|
||||
router
|
||||
.route('/:certificate_id')
|
||||
.route("/:certificate_id")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -119,30 +120,32 @@ router
|
||||
* Retrieve a specific certificate
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
validator({
|
||||
required: ['certificate_id'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
certificate_id: {
|
||||
$ref: 'common#/properties/id'
|
||||
validator(
|
||||
{
|
||||
required: ["certificate_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
certificate_id: {
|
||||
$ref: "common#/properties/id",
|
||||
},
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
},
|
||||
expand: {
|
||||
$ref: 'common#/properties/expand'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
certificate_id: req.params.certificate_id,
|
||||
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null)
|
||||
})
|
||||
},
|
||||
{
|
||||
certificate_id: req.params.certificate_id,
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalCertificate.get(res.locals.access, {
|
||||
id: parseInt(data.certificate_id, 10),
|
||||
expand: data.expand
|
||||
id: Number.parseInt(data.certificate_id, 10),
|
||||
expand: data.expand,
|
||||
});
|
||||
})
|
||||
.then((row) => {
|
||||
res.status(200)
|
||||
.send(row);
|
||||
res.status(200).send(row);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -153,10 +156,10 @@ router
|
||||
* Update and existing certificate
|
||||
*/
|
||||
.delete((req, res, next) => {
|
||||
internalCertificate.delete(res.locals.access, {id: parseInt(req.params.certificate_id, 10)})
|
||||
internalCertificate
|
||||
.delete(res.locals.access, { id: Number.parseInt(req.params.certificate_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -167,7 +170,7 @@ router
|
||||
* /api/nginx/certificates/123/upload
|
||||
*/
|
||||
router
|
||||
.route('/:certificate_id/upload')
|
||||
.route("/:certificate_id/upload")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -180,16 +183,15 @@ router
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
if (!req.files) {
|
||||
res.status(400)
|
||||
.send({error: 'No files were uploaded'});
|
||||
res.status(400).send({ error: "No files were uploaded" });
|
||||
} else {
|
||||
internalCertificate.upload(res.locals.access, {
|
||||
id: parseInt(req.params.certificate_id, 10),
|
||||
files: req.files
|
||||
})
|
||||
internalCertificate
|
||||
.upload(res.locals.access, {
|
||||
id: Number.parseInt(req.params.certificate_id, 10),
|
||||
files: req.files,
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
}
|
||||
@@ -201,7 +203,7 @@ router
|
||||
* /api/nginx/certificates/123/renew
|
||||
*/
|
||||
router
|
||||
.route('/:certificate_id/renew')
|
||||
.route("/:certificate_id/renew")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -214,12 +216,12 @@ router
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
req.setTimeout(900000); // 15 minutes timeout
|
||||
internalCertificate.renew(res.locals.access, {
|
||||
id: parseInt(req.params.certificate_id, 10)
|
||||
})
|
||||
internalCertificate
|
||||
.renew(res.locals.access, {
|
||||
id: Number.parseInt(req.params.certificate_id, 10),
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -230,7 +232,7 @@ router
|
||||
* /api/nginx/certificates/123/download
|
||||
*/
|
||||
router
|
||||
.route('/:certificate_id/download')
|
||||
.route("/:certificate_id/download")
|
||||
.options((_req, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -242,12 +244,12 @@ router
|
||||
* Renew certificate
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
internalCertificate.download(res.locals.access, {
|
||||
id: parseInt(req.params.certificate_id, 10)
|
||||
})
|
||||
internalCertificate
|
||||
.download(res.locals.access, {
|
||||
id: Number.parseInt(req.params.certificate_id, 10),
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.download(result.fileName);
|
||||
res.status(200).download(result.fileName);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -258,7 +260,7 @@ router
|
||||
* /api/nginx/certificates/validate
|
||||
*/
|
||||
router
|
||||
.route('/validate')
|
||||
.route("/validate")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -271,18 +273,17 @@ router
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
if (!req.files) {
|
||||
res.status(400)
|
||||
.send({error: 'No files were uploaded'});
|
||||
res.status(400).send({ error: "No files were uploaded" });
|
||||
} else {
|
||||
internalCertificate.validate({
|
||||
files: req.files
|
||||
})
|
||||
internalCertificate
|
||||
.validate({
|
||||
files: req.files,
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
export default router;
|
||||
|
@@ -1,21 +1,21 @@
|
||||
const express = require('express');
|
||||
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');
|
||||
import express from "express";
|
||||
import internalDeadHost from "../../internal/dead-host.js";
|
||||
import jwtdecode from "../../lib/express/jwt-decode.js";
|
||||
import apiValidator from "../../lib/validator/api.js";
|
||||
import validator from "../../lib/validator/index.js";
|
||||
import { getValidationSchema } from "../../schema/index.js";
|
||||
|
||||
let router = express.Router({
|
||||
const router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
strict: true,
|
||||
mergeParams: true,
|
||||
});
|
||||
|
||||
/**
|
||||
* /api/nginx/dead-hosts
|
||||
*/
|
||||
router
|
||||
.route('/')
|
||||
.route("/")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -27,26 +27,28 @@ router
|
||||
* Retrieve all dead-hosts
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
validator({
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: 'common#/properties/expand'
|
||||
validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
},
|
||||
query: {
|
||||
$ref: 'common#/properties/query'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null),
|
||||
query: (typeof req.query.query === 'string' ? req.query.query : null)
|
||||
})
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalDeadHost.getAll(res.locals.access, data.expand, data.query);
|
||||
})
|
||||
.then((rows) => {
|
||||
res.status(200)
|
||||
.send(rows);
|
||||
res.status(200).send(rows);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -57,13 +59,12 @@ router
|
||||
* Create a new dead-host
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
apiValidator(schema.getValidationSchema('/nginx/dead-hosts', 'post'), req.body)
|
||||
apiValidator(getValidationSchema("/nginx/dead-hosts", "post"), req.body)
|
||||
.then((payload) => {
|
||||
return internalDeadHost.create(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(201)
|
||||
.send(result);
|
||||
res.status(201).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -74,8 +75,8 @@ router
|
||||
* /api/nginx/dead-hosts/123
|
||||
*/
|
||||
router
|
||||
.route('/:host_id')
|
||||
.options((req, res) => {
|
||||
.route("/:host_id")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@@ -86,30 +87,32 @@ router
|
||||
* Retrieve a specific dead-host
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
validator({
|
||||
required: ['host_id'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
host_id: {
|
||||
$ref: 'common#/properties/id'
|
||||
validator(
|
||||
{
|
||||
required: ["host_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
host_id: {
|
||||
$ref: "common#/properties/id",
|
||||
},
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
},
|
||||
expand: {
|
||||
$ref: 'common#/properties/expand'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
host_id: req.params.host_id,
|
||||
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null)
|
||||
})
|
||||
},
|
||||
{
|
||||
host_id: req.params.host_id,
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalDeadHost.get(res.locals.access, {
|
||||
id: parseInt(data.host_id, 10),
|
||||
expand: data.expand
|
||||
id: Number.parseInt(data.host_id, 10),
|
||||
expand: data.expand,
|
||||
});
|
||||
})
|
||||
.then((row) => {
|
||||
res.status(200)
|
||||
.send(row);
|
||||
res.status(200).send(row);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -120,14 +123,13 @@ router
|
||||
* Update and existing dead-host
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator(schema.getValidationSchema('/nginx/dead-hosts/{hostID}', 'put'), req.body)
|
||||
apiValidator(getValidationSchema("/nginx/dead-hosts/{hostID}", "put"), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = parseInt(req.params.host_id, 10);
|
||||
payload.id = Number.parseInt(req.params.host_id, 10);
|
||||
return internalDeadHost.update(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -138,10 +140,10 @@ router
|
||||
* Update and existing dead-host
|
||||
*/
|
||||
.delete((req, res, next) => {
|
||||
internalDeadHost.delete(res.locals.access, {id: parseInt(req.params.host_id, 10)})
|
||||
internalDeadHost
|
||||
.delete(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -152,7 +154,7 @@ router
|
||||
* /api/nginx/dead-hosts/123/enable
|
||||
*/
|
||||
router
|
||||
.route('/:host_id/enable')
|
||||
.route("/:host_id/enable")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -162,10 +164,10 @@ router
|
||||
* POST /api/nginx/dead-hosts/123/enable
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
internalDeadHost.enable(res.locals.access, {id: parseInt(req.params.host_id, 10)})
|
||||
internalDeadHost
|
||||
.enable(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -176,7 +178,7 @@ router
|
||||
* /api/nginx/dead-hosts/123/disable
|
||||
*/
|
||||
router
|
||||
.route('/:host_id/disable')
|
||||
.route("/:host_id/disable")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -186,12 +188,12 @@ router
|
||||
* POST /api/nginx/dead-hosts/123/disable
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
internalDeadHost.disable(res.locals.access, {id: parseInt(req.params.host_id, 10)})
|
||||
internalDeadHost
|
||||
.disable(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
export default router;
|
||||
|
@@ -1,22 +1,22 @@
|
||||
const express = require('express');
|
||||
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');
|
||||
import express from "express";
|
||||
import internalProxyHost from "../../internal/proxy-host.js";
|
||||
import jwtdecode from "../../lib/express/jwt-decode.js";
|
||||
import apiValidator from "../../lib/validator/api.js";
|
||||
import validator from "../../lib/validator/index.js";
|
||||
import { getValidationSchema } from "../../schema/index.js";
|
||||
|
||||
let router = express.Router({
|
||||
const router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
strict: true,
|
||||
mergeParams: true,
|
||||
});
|
||||
|
||||
/**
|
||||
* /api/nginx/proxy-hosts
|
||||
*/
|
||||
router
|
||||
.route('/')
|
||||
.options((req, res) => {
|
||||
.route("/")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@@ -27,26 +27,28 @@ router
|
||||
* Retrieve all proxy-hosts
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
validator({
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: 'common#/properties/expand'
|
||||
validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
},
|
||||
query: {
|
||||
$ref: 'common#/properties/query'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null),
|
||||
query: (typeof req.query.query === 'string' ? req.query.query : null)
|
||||
})
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalProxyHost.getAll(res.locals.access, data.expand, data.query);
|
||||
})
|
||||
.then((rows) => {
|
||||
res.status(200)
|
||||
.send(rows);
|
||||
res.status(200).send(rows);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -57,13 +59,12 @@ router
|
||||
* Create a new proxy-host
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
apiValidator(schema.getValidationSchema('/nginx/proxy-hosts', 'post'), req.body)
|
||||
apiValidator(getValidationSchema("/nginx/proxy-hosts", "post"), req.body)
|
||||
.then((payload) => {
|
||||
return internalProxyHost.create(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(201)
|
||||
.send(result);
|
||||
res.status(201).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -74,8 +75,8 @@ router
|
||||
* /api/nginx/proxy-hosts/123
|
||||
*/
|
||||
router
|
||||
.route('/:host_id')
|
||||
.options((req, res) => {
|
||||
.route("/:host_id")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@@ -86,30 +87,32 @@ router
|
||||
* Retrieve a specific proxy-host
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
validator({
|
||||
required: ['host_id'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
host_id: {
|
||||
$ref: 'common#/properties/id'
|
||||
validator(
|
||||
{
|
||||
required: ["host_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
host_id: {
|
||||
$ref: "common#/properties/id",
|
||||
},
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
},
|
||||
expand: {
|
||||
$ref: 'common#/properties/expand'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
host_id: req.params.host_id,
|
||||
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null)
|
||||
})
|
||||
},
|
||||
{
|
||||
host_id: req.params.host_id,
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalProxyHost.get(res.locals.access, {
|
||||
id: parseInt(data.host_id, 10),
|
||||
expand: data.expand
|
||||
id: Number.parseInt(data.host_id, 10),
|
||||
expand: data.expand,
|
||||
});
|
||||
})
|
||||
.then((row) => {
|
||||
res.status(200)
|
||||
.send(row);
|
||||
res.status(200).send(row);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -120,14 +123,13 @@ router
|
||||
* Update and existing proxy-host
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator(schema.getValidationSchema('/nginx/proxy-hosts/{hostID}', 'put'), req.body)
|
||||
apiValidator(getValidationSchema("/nginx/proxy-hosts/{hostID}", "put"), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = parseInt(req.params.host_id, 10);
|
||||
payload.id = Number.parseInt(req.params.host_id, 10);
|
||||
return internalProxyHost.update(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -138,10 +140,10 @@ router
|
||||
* Update and existing proxy-host
|
||||
*/
|
||||
.delete((req, res, next) => {
|
||||
internalProxyHost.delete(res.locals.access, {id: parseInt(req.params.host_id, 10)})
|
||||
internalProxyHost
|
||||
.delete(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -152,7 +154,7 @@ router
|
||||
* /api/nginx/proxy-hosts/123/enable
|
||||
*/
|
||||
router
|
||||
.route('/:host_id/enable')
|
||||
.route("/:host_id/enable")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -162,10 +164,10 @@ router
|
||||
* POST /api/nginx/proxy-hosts/123/enable
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
internalProxyHost.enable(res.locals.access, {id: parseInt(req.params.host_id, 10)})
|
||||
internalProxyHost
|
||||
.enable(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -176,7 +178,7 @@ router
|
||||
* /api/nginx/proxy-hosts/123/disable
|
||||
*/
|
||||
router
|
||||
.route('/:host_id/disable')
|
||||
.route("/:host_id/disable")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -186,12 +188,12 @@ router
|
||||
* POST /api/nginx/proxy-hosts/123/disable
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
internalProxyHost.disable(res.locals.access, {id: parseInt(req.params.host_id, 10)})
|
||||
internalProxyHost
|
||||
.disable(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
export default router;
|
||||
|
@@ -1,22 +1,22 @@
|
||||
const express = require('express');
|
||||
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');
|
||||
import express from "express";
|
||||
import internalRedirectionHost from "../../internal/redirection-host.js";
|
||||
import jwtdecode from "../../lib/express/jwt-decode.js";
|
||||
import apiValidator from "../../lib/validator/api.js";
|
||||
import validator from "../../lib/validator/index.js";
|
||||
import { getValidationSchema } from "../../schema/index.js";
|
||||
|
||||
let router = express.Router({
|
||||
const router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
strict: true,
|
||||
mergeParams: true,
|
||||
});
|
||||
|
||||
/**
|
||||
* /api/nginx/redirection-hosts
|
||||
*/
|
||||
router
|
||||
.route('/')
|
||||
.options((req, res) => {
|
||||
.route("/")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@@ -27,26 +27,28 @@ router
|
||||
* Retrieve all redirection-hosts
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
validator({
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: 'common#/properties/expand'
|
||||
validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
},
|
||||
query: {
|
||||
$ref: 'common#/properties/query'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null),
|
||||
query: (typeof req.query.query === 'string' ? req.query.query : null)
|
||||
})
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalRedirectionHost.getAll(res.locals.access, data.expand, data.query);
|
||||
})
|
||||
.then((rows) => {
|
||||
res.status(200)
|
||||
.send(rows);
|
||||
res.status(200).send(rows);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -57,13 +59,12 @@ router
|
||||
* Create a new redirection-host
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
apiValidator(schema.getValidationSchema('/nginx/redirection-hosts', 'post'), req.body)
|
||||
apiValidator(getValidationSchema("/nginx/redirection-hosts", "post"), req.body)
|
||||
.then((payload) => {
|
||||
return internalRedirectionHost.create(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(201)
|
||||
.send(result);
|
||||
res.status(201).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -74,8 +75,8 @@ router
|
||||
* /api/nginx/redirection-hosts/123
|
||||
*/
|
||||
router
|
||||
.route('/:host_id')
|
||||
.options((req, res) => {
|
||||
.route("/:host_id")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@@ -86,30 +87,32 @@ router
|
||||
* Retrieve a specific redirection-host
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
validator({
|
||||
required: ['host_id'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
host_id: {
|
||||
$ref: 'common#/properties/id'
|
||||
validator(
|
||||
{
|
||||
required: ["host_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
host_id: {
|
||||
$ref: "common#/properties/id",
|
||||
},
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
},
|
||||
expand: {
|
||||
$ref: 'common#/properties/expand'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
host_id: req.params.host_id,
|
||||
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null)
|
||||
})
|
||||
},
|
||||
{
|
||||
host_id: req.params.host_id,
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalRedirectionHost.get(res.locals.access, {
|
||||
id: parseInt(data.host_id, 10),
|
||||
expand: data.expand
|
||||
id: Number.parseInt(data.host_id, 10),
|
||||
expand: data.expand,
|
||||
});
|
||||
})
|
||||
.then((row) => {
|
||||
res.status(200)
|
||||
.send(row);
|
||||
res.status(200).send(row);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -120,14 +123,13 @@ router
|
||||
* Update and existing redirection-host
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator(schema.getValidationSchema('/nginx/redirection-hosts/{hostID}', 'put'), req.body)
|
||||
apiValidator(getValidationSchema("/nginx/redirection-hosts/{hostID}", "put"), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = parseInt(req.params.host_id, 10);
|
||||
payload.id = Number.parseInt(req.params.host_id, 10);
|
||||
return internalRedirectionHost.update(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -138,10 +140,10 @@ router
|
||||
* Update and existing redirection-host
|
||||
*/
|
||||
.delete((req, res, next) => {
|
||||
internalRedirectionHost.delete(res.locals.access, {id: parseInt(req.params.host_id, 10)})
|
||||
internalRedirectionHost
|
||||
.delete(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -152,8 +154,8 @@ router
|
||||
* /api/nginx/redirection-hosts/123/enable
|
||||
*/
|
||||
router
|
||||
.route('/:host_id/enable')
|
||||
.options((req, res) => {
|
||||
.route("/:host_id/enable")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@@ -162,10 +164,10 @@ router
|
||||
* POST /api/nginx/redirection-hosts/123/enable
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
internalRedirectionHost.enable(res.locals.access, {id: parseInt(req.params.host_id, 10)})
|
||||
internalRedirectionHost
|
||||
.enable(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -176,8 +178,8 @@ router
|
||||
* /api/nginx/redirection-hosts/123/disable
|
||||
*/
|
||||
router
|
||||
.route('/:host_id/disable')
|
||||
.options((req, res) => {
|
||||
.route("/:host_id/disable")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@@ -186,12 +188,12 @@ router
|
||||
* POST /api/nginx/redirection-hosts/123/disable
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
internalRedirectionHost.disable(res.locals.access, {id: parseInt(req.params.host_id, 10)})
|
||||
internalRedirectionHost
|
||||
.disable(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
export default router;
|
||||
|
@@ -1,22 +1,22 @@
|
||||
const express = require('express');
|
||||
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');
|
||||
import express from "express";
|
||||
import internalStream from "../../internal/stream.js";
|
||||
import jwtdecode from "../../lib/express/jwt-decode.js";
|
||||
import apiValidator from "../../lib/validator/api.js";
|
||||
import validator from "../../lib/validator/index.js";
|
||||
import { getValidationSchema } from "../../schema/index.js";
|
||||
|
||||
let router = express.Router({
|
||||
const router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
strict: true,
|
||||
mergeParams: true,
|
||||
});
|
||||
|
||||
/**
|
||||
* /api/nginx/streams
|
||||
*/
|
||||
router
|
||||
.route('/')
|
||||
.options((req, res) => {
|
||||
.route("/")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode()) // preferred so it doesn't apply to nonexistent routes
|
||||
@@ -27,26 +27,28 @@ router
|
||||
* Retrieve all streams
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
validator({
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: 'common#/properties/expand'
|
||||
validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
},
|
||||
query: {
|
||||
$ref: 'common#/properties/query'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null),
|
||||
query: (typeof req.query.query === 'string' ? req.query.query : null)
|
||||
})
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalStream.getAll(res.locals.access, data.expand, data.query);
|
||||
})
|
||||
.then((rows) => {
|
||||
res.status(200)
|
||||
.send(rows);
|
||||
res.status(200).send(rows);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -57,13 +59,12 @@ router
|
||||
* Create a new stream
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
apiValidator(schema.getValidationSchema('/nginx/streams', 'post'), req.body)
|
||||
apiValidator(getValidationSchema("/nginx/streams", "post"), req.body)
|
||||
.then((payload) => {
|
||||
return internalStream.create(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(201)
|
||||
.send(result);
|
||||
res.status(201).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -74,8 +75,8 @@ router
|
||||
* /api/nginx/streams/123
|
||||
*/
|
||||
router
|
||||
.route('/:stream_id')
|
||||
.options((req, res) => {
|
||||
.route("/:stream_id")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode()) // preferred so it doesn't apply to nonexistent routes
|
||||
@@ -86,30 +87,32 @@ router
|
||||
* Retrieve a specific stream
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
validator({
|
||||
required: ['stream_id'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
stream_id: {
|
||||
$ref: 'common#/properties/id'
|
||||
validator(
|
||||
{
|
||||
required: ["stream_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
stream_id: {
|
||||
$ref: "common#/properties/id",
|
||||
},
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
},
|
||||
expand: {
|
||||
$ref: 'common#/properties/expand'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
stream_id: req.params.stream_id,
|
||||
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null)
|
||||
})
|
||||
},
|
||||
{
|
||||
stream_id: req.params.stream_id,
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalStream.get(res.locals.access, {
|
||||
id: parseInt(data.stream_id, 10),
|
||||
expand: data.expand
|
||||
id: Number.parseInt(data.stream_id, 10),
|
||||
expand: data.expand,
|
||||
});
|
||||
})
|
||||
.then((row) => {
|
||||
res.status(200)
|
||||
.send(row);
|
||||
res.status(200).send(row);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -120,14 +123,13 @@ router
|
||||
* Update and existing stream
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator(schema.getValidationSchema('/nginx/streams/{streamID}', 'put'), req.body)
|
||||
apiValidator(getValidationSchema("/nginx/streams/{streamID}", "put"), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = parseInt(req.params.stream_id, 10);
|
||||
payload.id = Number.parseInt(req.params.stream_id, 10);
|
||||
return internalStream.update(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -138,10 +140,10 @@ router
|
||||
* Update and existing stream
|
||||
*/
|
||||
.delete((req, res, next) => {
|
||||
internalStream.delete(res.locals.access, {id: parseInt(req.params.stream_id, 10)})
|
||||
internalStream
|
||||
.delete(res.locals.access, { id: Number.parseInt(req.params.stream_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -152,7 +154,7 @@ router
|
||||
* /api/nginx/streams/123/enable
|
||||
*/
|
||||
router
|
||||
.route('/:host_id/enable')
|
||||
.route("/:host_id/enable")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -162,10 +164,10 @@ router
|
||||
* POST /api/nginx/streams/123/enable
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
internalStream.enable(res.locals.access, {id: parseInt(req.params.host_id, 10)})
|
||||
internalStream
|
||||
.enable(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -176,7 +178,7 @@ router
|
||||
* /api/nginx/streams/123/disable
|
||||
*/
|
||||
router
|
||||
.route('/:host_id/disable')
|
||||
.route("/:host_id/disable")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -186,12 +188,12 @@ router
|
||||
* POST /api/nginx/streams/123/disable
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
internalStream.disable(res.locals.access, {id: parseInt(req.params.host_id, 10)})
|
||||
internalStream
|
||||
.disable(res.locals.access, { id: Number.parseInt(req.params.host_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
export default router;
|
||||
|
@@ -1,15 +1,15 @@
|
||||
const express = require('express');
|
||||
const jwtdecode = require('../lib/express/jwt-decode');
|
||||
const internalReport = require('../internal/report');
|
||||
import express from "express";
|
||||
import internalReport from "../internal/report.js";
|
||||
import jwtdecode from "../lib/express/jwt-decode.js";
|
||||
|
||||
let router = express.Router({
|
||||
const router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
strict: true,
|
||||
mergeParams: true,
|
||||
});
|
||||
|
||||
router
|
||||
.route('/hosts')
|
||||
.route("/hosts")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -18,12 +18,12 @@ router
|
||||
* GET /reports/hosts
|
||||
*/
|
||||
.get(jwtdecode(), (_, res, next) => {
|
||||
internalReport.getHostsReport(res.locals.access)
|
||||
internalReport
|
||||
.getHostsReport(res.locals.access)
|
||||
.then((data) => {
|
||||
res.status(200)
|
||||
.send(data);
|
||||
res.status(200).send(data);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
export default router;
|
||||
|
@@ -1,15 +1,15 @@
|
||||
const express = require('express');
|
||||
const schema = require('../schema');
|
||||
const PACKAGE = require('../package.json');
|
||||
import express from "express";
|
||||
import PACKAGE from "../package.json" with { type: "json" };
|
||||
import { getCompiledSchema } from "../schema/index.js";
|
||||
|
||||
const router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
strict: true,
|
||||
mergeParams: true,
|
||||
});
|
||||
|
||||
router
|
||||
.route('/')
|
||||
.route("/")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -18,21 +18,21 @@ router
|
||||
* GET /schema
|
||||
*/
|
||||
.get(async (req, res) => {
|
||||
let swaggerJSON = await schema.getCompiledSchema();
|
||||
const swaggerJSON = await getCompiledSchema();
|
||||
|
||||
let proto = req.protocol;
|
||||
if (typeof req.headers['x-forwarded-proto'] !== 'undefined' && req.headers['x-forwarded-proto']) {
|
||||
proto = req.headers['x-forwarded-proto'];
|
||||
if (typeof req.headers["x-forwarded-proto"] !== "undefined" && req.headers["x-forwarded-proto"]) {
|
||||
proto = req.headers["x-forwarded-proto"];
|
||||
}
|
||||
|
||||
let origin = proto + '://' + req.hostname;
|
||||
if (typeof req.headers.origin !== 'undefined' && req.headers.origin) {
|
||||
let origin = `${proto}://${req.hostname}`;
|
||||
if (typeof req.headers.origin !== "undefined" && req.headers.origin) {
|
||||
origin = req.headers.origin;
|
||||
}
|
||||
|
||||
swaggerJSON.info.version = PACKAGE.version;
|
||||
swaggerJSON.servers[0].url = origin + '/api';
|
||||
swaggerJSON.info.version = PACKAGE.version;
|
||||
swaggerJSON.servers[0].url = `${origin}/api`;
|
||||
res.status(200).send(swaggerJSON);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
export default router;
|
||||
|
@@ -1,21 +1,21 @@
|
||||
const express = require('express');
|
||||
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');
|
||||
import express from "express";
|
||||
import internalSetting from "../internal/setting.js";
|
||||
import jwtdecode from "../lib/express/jwt-decode.js";
|
||||
import apiValidator from "../lib/validator/api.js";
|
||||
import validator from "../lib/validator/index.js";
|
||||
import { getValidationSchema } from "../schema/index.js";
|
||||
|
||||
let router = express.Router({
|
||||
const router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
strict: true,
|
||||
mergeParams: true,
|
||||
});
|
||||
|
||||
/**
|
||||
* /api/settings
|
||||
*/
|
||||
router
|
||||
.route('/')
|
||||
.route("/")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -27,10 +27,10 @@ router
|
||||
* Retrieve all settings
|
||||
*/
|
||||
.get((_, res, next) => {
|
||||
internalSetting.getAll(res.locals.access)
|
||||
internalSetting
|
||||
.getAll(res.locals.access)
|
||||
.then((rows) => {
|
||||
res.status(200)
|
||||
.send(rows);
|
||||
res.status(200).send(rows);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -41,7 +41,7 @@ router
|
||||
* /api/settings/something
|
||||
*/
|
||||
router
|
||||
.route('/:setting_id')
|
||||
.route("/:setting_id")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -53,26 +53,28 @@ router
|
||||
* Retrieve a specific setting
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
validator({
|
||||
required: ['setting_id'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
setting_id: {
|
||||
type: 'string',
|
||||
minLength: 1
|
||||
}
|
||||
}
|
||||
}, {
|
||||
setting_id: req.params.setting_id
|
||||
})
|
||||
validator(
|
||||
{
|
||||
required: ["setting_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
setting_id: {
|
||||
type: "string",
|
||||
minLength: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
setting_id: req.params.setting_id,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalSetting.get(res.locals.access, {
|
||||
id: data.setting_id
|
||||
id: data.setting_id,
|
||||
});
|
||||
})
|
||||
.then((row) => {
|
||||
res.status(200)
|
||||
.send(row);
|
||||
res.status(200).send(row);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -83,16 +85,15 @@ router
|
||||
* Update and existing setting
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator(schema.getValidationSchema('/settings/{settingID}', 'put'), req.body)
|
||||
apiValidator(getValidationSchema("/settings/{settingID}", "put"), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = req.params.setting_id;
|
||||
return internalSetting.update(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
export default router;
|
||||
|
@@ -1,17 +1,17 @@
|
||||
const express = require('express');
|
||||
const jwtdecode = require('../lib/express/jwt-decode');
|
||||
const apiValidator = require('../lib/validator/api');
|
||||
const internalToken = require('../internal/token');
|
||||
const schema = require('../schema');
|
||||
import express from "express";
|
||||
import internalToken from "../internal/token.js";
|
||||
import jwtdecode from "../lib/express/jwt-decode.js";
|
||||
import apiValidator from "../lib/validator/api.js";
|
||||
import { getValidationSchema } from "../schema/index.js";
|
||||
|
||||
let router = express.Router({
|
||||
const router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
strict: true,
|
||||
mergeParams: true,
|
||||
});
|
||||
|
||||
router
|
||||
.route('/')
|
||||
.route("/")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -24,13 +24,13 @@ router
|
||||
* for services like Job board and Worker.
|
||||
*/
|
||||
.get(jwtdecode(), (req, res, next) => {
|
||||
internalToken.getFreshToken(res.locals.access, {
|
||||
expiry: (typeof req.query.expiry !== 'undefined' ? req.query.expiry : null),
|
||||
scope: (typeof req.query.scope !== 'undefined' ? req.query.scope : null)
|
||||
})
|
||||
internalToken
|
||||
.getFreshToken(res.locals.access, {
|
||||
expiry: typeof req.query.expiry !== "undefined" ? req.query.expiry : null,
|
||||
scope: typeof req.query.scope !== "undefined" ? req.query.scope : null,
|
||||
})
|
||||
.then((data) => {
|
||||
res.status(200)
|
||||
.send(data);
|
||||
res.status(200).send(data);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -41,13 +41,12 @@ router
|
||||
* Create a new Token
|
||||
*/
|
||||
.post(async (req, res, next) => {
|
||||
apiValidator(schema.getValidationSchema('/tokens', 'post'), req.body)
|
||||
apiValidator(getValidationSchema("/tokens", "post"), req.body)
|
||||
.then(internalToken.getTokenFromEmail)
|
||||
.then((data) => {
|
||||
res.status(200)
|
||||
.send(data);
|
||||
res.status(200).send(data);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
export default router;
|
||||
|
@@ -1,22 +1,22 @@
|
||||
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 schema = require('../schema');
|
||||
import express from "express";
|
||||
import internalUser from "../internal/user.js";
|
||||
import jwtdecode from "../lib/express/jwt-decode.js";
|
||||
import userIdFromMe from "../lib/express/user-id-from-me.js";
|
||||
import apiValidator from "../lib/validator/api.js";
|
||||
import validator from "../lib/validator/index.js";
|
||||
import { getValidationSchema } from "../schema/index.js";
|
||||
|
||||
let router = express.Router({
|
||||
const router = express.Router({
|
||||
caseSensitive: true,
|
||||
strict: true,
|
||||
mergeParams: true
|
||||
strict: true,
|
||||
mergeParams: true,
|
||||
});
|
||||
|
||||
/**
|
||||
* /api/users
|
||||
*/
|
||||
router
|
||||
.route('/')
|
||||
.route("/")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -28,26 +28,28 @@ router
|
||||
* Retrieve all users
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
validator({
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: 'common#/properties/expand'
|
||||
validator(
|
||||
{
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
query: {
|
||||
$ref: "common#/properties/query",
|
||||
},
|
||||
},
|
||||
query: {
|
||||
$ref: 'common#/properties/query'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null),
|
||||
query: (typeof req.query.query === 'string' ? req.query.query : null)
|
||||
})
|
||||
},
|
||||
{
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
query: typeof req.query.query === "string" ? req.query.query : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalUser.getAll(res.locals.access, data.expand, data.query);
|
||||
})
|
||||
.then((users) => {
|
||||
res.status(200)
|
||||
.send(users);
|
||||
res.status(200).send(users);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
@@ -62,13 +64,12 @@ router
|
||||
* Create a new User
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
apiValidator(schema.getValidationSchema('/users', 'post'), req.body)
|
||||
apiValidator(getValidationSchema("/users", "post"), req.body)
|
||||
.then((payload) => {
|
||||
return internalUser.create(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(201)
|
||||
.send(result);
|
||||
res.status(201).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -79,7 +80,7 @@ router
|
||||
* /api/users/123
|
||||
*/
|
||||
router
|
||||
.route('/:user_id')
|
||||
.route("/:user_id")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -92,31 +93,33 @@ router
|
||||
* Retrieve a specific user
|
||||
*/
|
||||
.get((req, res, next) => {
|
||||
validator({
|
||||
required: ['user_id'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
user_id: {
|
||||
$ref: 'common#/properties/id'
|
||||
validator(
|
||||
{
|
||||
required: ["user_id"],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
user_id: {
|
||||
$ref: "common#/properties/id",
|
||||
},
|
||||
expand: {
|
||||
$ref: "common#/properties/expand",
|
||||
},
|
||||
},
|
||||
expand: {
|
||||
$ref: 'common#/properties/expand'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
user_id: req.params.user_id,
|
||||
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null)
|
||||
})
|
||||
},
|
||||
{
|
||||
user_id: req.params.user_id,
|
||||
expand: typeof req.query.expand === "string" ? req.query.expand.split(",") : null,
|
||||
},
|
||||
)
|
||||
.then((data) => {
|
||||
return internalUser.get(res.locals.access, {
|
||||
id: data.user_id,
|
||||
id: data.user_id,
|
||||
expand: data.expand,
|
||||
omit: internalUser.getUserOmisionsByAccess(res.locals.access, data.user_id)
|
||||
omit: internalUser.getUserOmisionsByAccess(res.locals.access, data.user_id),
|
||||
});
|
||||
})
|
||||
.then((user) => {
|
||||
res.status(200)
|
||||
.send(user);
|
||||
res.status(200).send(user);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
@@ -130,14 +133,13 @@ router
|
||||
* Update and existing user
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator(schema.getValidationSchema('/users/{userID}', 'put'), req.body)
|
||||
apiValidator(getValidationSchema("/users/{userID}", "put"), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = req.params.user_id;
|
||||
return internalUser.update(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
})
|
||||
@@ -148,10 +150,10 @@ router
|
||||
* Update and existing user
|
||||
*/
|
||||
.delete((req, res, next) => {
|
||||
internalUser.delete(res.locals.access, {id: req.params.user_id})
|
||||
internalUser
|
||||
.delete(res.locals.access, { id: req.params.user_id })
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -162,8 +164,8 @@ router
|
||||
* /api/users/123/auth
|
||||
*/
|
||||
router
|
||||
.route('/:user_id/auth')
|
||||
.options((req, res) => {
|
||||
.route("/:user_id/auth")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@@ -175,14 +177,13 @@ router
|
||||
* Update password for a user
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator(schema.getValidationSchema('/users/{userID}/auth', 'put'), req.body)
|
||||
apiValidator(getValidationSchema("/users/{userID}/auth", "put"), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = req.params.user_id;
|
||||
return internalUser.setPassword(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -193,8 +194,8 @@ router
|
||||
* /api/users/123/permissions
|
||||
*/
|
||||
router
|
||||
.route('/:user_id/permissions')
|
||||
.options((req, res) => {
|
||||
.route("/:user_id/permissions")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
.all(jwtdecode())
|
||||
@@ -206,14 +207,13 @@ router
|
||||
* Set some or all permissions for a user
|
||||
*/
|
||||
.put((req, res, next) => {
|
||||
apiValidator(schema.getValidationSchema('/users/{userID}/permissions', 'put'), req.body)
|
||||
apiValidator(getValidationSchema("/users/{userID}/permissions", "put"), req.body)
|
||||
.then((payload) => {
|
||||
payload.id = req.params.user_id;
|
||||
return internalUser.setPermissions(res.locals.access, payload);
|
||||
})
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
@@ -224,7 +224,7 @@ router
|
||||
* /api/users/123/login
|
||||
*/
|
||||
router
|
||||
.route('/:user_id/login')
|
||||
.route("/:user_id/login")
|
||||
.options((_, res) => {
|
||||
res.sendStatus(204);
|
||||
})
|
||||
@@ -236,12 +236,12 @@ router
|
||||
* Log in as a user
|
||||
*/
|
||||
.post((req, res, next) => {
|
||||
internalUser.loginAs(res.locals.access, {id: parseInt(req.params.user_id, 10)})
|
||||
internalUser
|
||||
.loginAs(res.locals.access, { id: Number.parseInt(req.params.user_id, 10) })
|
||||
.then((result) => {
|
||||
res.status(200)
|
||||
.send(result);
|
||||
res.status(200).send(result);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
export default router;
|
||||
|
Reference in New Issue
Block a user