You've already forked nginx-proxy-manager
mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2025-06-15 14:01:41 +03: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:
38
backend/routes/schema.js
Normal file
38
backend/routes/schema.js
Normal file
@ -0,0 +1,38 @@
|
||||
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;
|
Reference in New Issue
Block a user