mirror of
https://github.com/xiaoxinpro/nginx-proxy-manager-zh.git
synced 2025-01-22 12:58:13 -05:00
dfe2588523
- /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
39 lines
900 B
JavaScript
39 lines
900 B
JavaScript
const express = require('express');
|
|
const schema = require('../schema');
|
|
const PACKAGE = require('../package.json');
|
|
|
|
const router = express.Router({
|
|
caseSensitive: true,
|
|
strict: true,
|
|
mergeParams: true
|
|
});
|
|
|
|
router
|
|
.route('/')
|
|
.options((_, res) => {
|
|
res.sendStatus(204);
|
|
})
|
|
|
|
/**
|
|
* GET /schema
|
|
*/
|
|
.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'];
|
|
}
|
|
|
|
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';
|
|
res.status(200).send(swaggerJSON);
|
|
});
|
|
|
|
module.exports = router;
|