2024-10-09 04:05:15 -04:00
|
|
|
const express = require('express');
|
|
|
|
const schema = require('../schema');
|
|
|
|
const PACKAGE = require('../package.json');
|
2020-02-18 23:55:06 -05:00
|
|
|
|
2024-10-09 04:05:15 -04:00
|
|
|
const router = express.Router({
|
2020-02-18 23:55:06 -05:00
|
|
|
caseSensitive: true,
|
|
|
|
strict: true,
|
|
|
|
mergeParams: true
|
|
|
|
});
|
|
|
|
|
|
|
|
router
|
|
|
|
.route('/')
|
2024-10-09 04:05:15 -04:00
|
|
|
.options((_, res) => {
|
2020-02-18 23:55:06 -05:00
|
|
|
res.sendStatus(204);
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GET /schema
|
|
|
|
*/
|
2024-10-09 04:05:15 -04:00
|
|
|
.get(async (req, res) => {
|
|
|
|
let swaggerJSON = await schema.getCompiledSchema();
|
|
|
|
|
2020-02-18 23:55:06 -05:00
|
|
|
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;
|