mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-01-25 02:08:24 +00:00
* initial changes for env var support
* WIP
* Update applications.js
* JSON stringify before encrypting
* use call_hook.url
* env vars working
GET /v1/AppEnv?url=[URL] to trigger options request to URL and return app-schema
POST /v1/Applications with {env_vars: [OBJECT} to create app with env vars
PUT /v1/Applications/[SID] with {env_vars: [OBJECT} to change env vars
GET returns env vars
POST and PUT will also trigger an OPTIONS request to the call_hook url to get schema and then validate the env_vars against it
* update appenv cannot finish request.
* wip
* wip
* wip
* wip
---------
Co-authored-by: Dave Horton <daveh@beachdognet.com>
Co-authored-by: Quan HL <quan.luuhoang8@gmail.com>
Co-authored-by: Hoan Luu Huu <110280845+xquanluu@users.noreply.github.com>
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
const router = require('express').Router();
|
|
const sysError = require('../error');
|
|
const { fetchAppEnvSchema, validateAppEnvSchema } = require('../../utils/appenv_utils');
|
|
|
|
const URL = require('url').URL;
|
|
|
|
const isValidUrl = (s) => {
|
|
const protocols = ['https:', 'http:', 'ws:', 'wss:'];
|
|
try {
|
|
const url = new URL(s);
|
|
if (protocols.includes(url.protocol)) {
|
|
return true;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
} catch (err) {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
/* get appenv schema for endpoint */
|
|
router.get('/', async(req, res) => {
|
|
const logger = req.app.locals.logger;
|
|
const url = req.query.url;
|
|
if (!isValidUrl(url)) {
|
|
sysError(logger, res, 'Invalid URL');
|
|
} else {
|
|
try {
|
|
const appenv = await fetchAppEnvSchema(logger, url);
|
|
if (appenv && validateAppEnvSchema(appenv)) {
|
|
return res.status(200).json(appenv);
|
|
} else if (appenv) {
|
|
return res.status(400).json({
|
|
msg: 'Invalid appenv schema',
|
|
});
|
|
} else {
|
|
return res.status(204).end(); //No appenv returned from url, normal scenario
|
|
}
|
|
}
|
|
catch (err) {
|
|
sysError(logger, res, err);
|
|
}
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|