2017-08-22 23:26:29 +02:00
|
|
|
/**
|
|
|
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
**/
|
|
|
|
|
|
|
|
var express = require("express");
|
|
|
|
|
|
|
|
var nodes = require("./nodes");
|
|
|
|
var flows = require("./flows");
|
|
|
|
var flow = require("./flow");
|
2018-06-27 00:34:32 +02:00
|
|
|
var context = require("./context");
|
2017-08-22 23:26:29 +02:00
|
|
|
var auth = require("../auth");
|
2020-07-31 16:26:21 +02:00
|
|
|
var info = require("./settings");
|
2020-12-10 17:01:55 +01:00
|
|
|
var plugins = require("./plugins");
|
2022-03-24 17:00:45 +01:00
|
|
|
var diagnostics = require("./diagnostics");
|
2017-08-22 23:26:29 +02:00
|
|
|
|
|
|
|
var apiUtil = require("../util");
|
|
|
|
|
|
|
|
module.exports = {
|
2020-07-31 16:26:21 +02:00
|
|
|
init: function(settings,runtimeAPI) {
|
2018-04-15 12:18:10 +02:00
|
|
|
flows.init(runtimeAPI);
|
|
|
|
flow.init(runtimeAPI);
|
|
|
|
nodes.init(runtimeAPI);
|
2018-07-30 00:47:19 +02:00
|
|
|
context.init(runtimeAPI);
|
2020-07-31 16:26:21 +02:00
|
|
|
info.init(settings,runtimeAPI);
|
2020-12-10 17:01:55 +01:00
|
|
|
plugins.init(runtimeAPI);
|
2022-03-28 19:49:56 +02:00
|
|
|
diagnostics.init(settings, runtimeAPI);
|
2017-08-22 23:26:29 +02:00
|
|
|
|
|
|
|
var needsPermission = auth.needsPermission;
|
|
|
|
|
|
|
|
var adminApp = express();
|
|
|
|
|
2021-06-08 22:17:42 +02:00
|
|
|
var defaultServerSettings = {
|
|
|
|
"x-powered-by": false
|
|
|
|
}
|
|
|
|
var serverSettings = Object.assign({},defaultServerSettings,settings.httpServerOptions||{});
|
|
|
|
for (var eOption in serverSettings) {
|
|
|
|
adminApp.set(eOption, serverSettings[eOption]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-22 23:26:29 +02:00
|
|
|
// Flows
|
|
|
|
adminApp.get("/flows",needsPermission("flows.read"),flows.get,apiUtil.errorHandler);
|
|
|
|
adminApp.post("/flows",needsPermission("flows.write"),flows.post,apiUtil.errorHandler);
|
|
|
|
|
2022-06-08 22:56:17 +02:00
|
|
|
// Flows/state
|
|
|
|
adminApp.get("/flows/state", needsPermission("flows.read"), flows.getState, apiUtil.errorHandler);
|
2022-06-27 19:06:53 +02:00
|
|
|
if (settings.runtimeState && settings.runtimeState.enabled === true) {
|
2022-06-08 22:56:17 +02:00
|
|
|
adminApp.post("/flows/state", needsPermission("flows.write"), flows.postState, apiUtil.errorHandler);
|
|
|
|
}
|
|
|
|
|
2017-08-22 23:26:29 +02:00
|
|
|
// Flow
|
|
|
|
adminApp.get("/flow/:id",needsPermission("flows.read"),flow.get,apiUtil.errorHandler);
|
|
|
|
adminApp.post("/flow",needsPermission("flows.write"),flow.post,apiUtil.errorHandler);
|
|
|
|
adminApp.delete("/flow/:id",needsPermission("flows.write"),flow.delete,apiUtil.errorHandler);
|
|
|
|
adminApp.put("/flow/:id",needsPermission("flows.write"),flow.put,apiUtil.errorHandler);
|
|
|
|
|
|
|
|
// Nodes
|
|
|
|
adminApp.get("/nodes",needsPermission("nodes.read"),nodes.getAll,apiUtil.errorHandler);
|
2020-08-13 16:54:54 +02:00
|
|
|
|
2020-12-27 13:49:17 +01:00
|
|
|
if (!settings.externalModules || !settings.externalModules.palette || settings.externalModules.palette.allowInstall !== false) {
|
|
|
|
if (!settings.externalModules || !settings.externalModules.palette || settings.externalModules.palette.allowUpload !== false) {
|
|
|
|
const multer = require('multer');
|
|
|
|
const upload = multer({ storage: multer.memoryStorage() });
|
|
|
|
adminApp.post("/nodes",needsPermission("nodes.write"),upload.single("tarball"),nodes.post,apiUtil.errorHandler);
|
|
|
|
} else {
|
|
|
|
adminApp.post("/nodes",needsPermission("nodes.write"),nodes.post,apiUtil.errorHandler);
|
|
|
|
}
|
2020-08-13 16:54:54 +02:00
|
|
|
}
|
2019-07-25 18:18:59 +02:00
|
|
|
adminApp.get(/^\/nodes\/messages/,needsPermission("nodes.read"),nodes.getModuleCatalogs,apiUtil.errorHandler);
|
|
|
|
adminApp.get(/^\/nodes\/((@[^\/]+\/)?[^\/]+\/[^\/]+)\/messages/,needsPermission("nodes.read"),nodes.getModuleCatalog,apiUtil.errorHandler);
|
|
|
|
adminApp.get(/^\/nodes\/((@[^\/]+\/)?[^\/]+)$/,needsPermission("nodes.read"),nodes.getModule,apiUtil.errorHandler);
|
|
|
|
adminApp.put(/^\/nodes\/((@[^\/]+\/)?[^\/]+)$/,needsPermission("nodes.write"),nodes.putModule,apiUtil.errorHandler);
|
|
|
|
adminApp.delete(/^\/nodes\/((@[^\/]+\/)?[^\/]+)$/,needsPermission("nodes.write"),nodes.delete,apiUtil.errorHandler);
|
|
|
|
adminApp.get(/^\/nodes\/((@[^\/]+\/)?[^\/]+)\/([^\/]+)$/,needsPermission("nodes.read"),nodes.getSet,apiUtil.errorHandler);
|
|
|
|
adminApp.put(/^\/nodes\/((@[^\/]+\/)?[^\/]+)\/([^\/]+)$/,needsPermission("nodes.write"),nodes.putSet,apiUtil.errorHandler);
|
2017-08-22 23:26:29 +02:00
|
|
|
|
2018-06-27 00:34:32 +02:00
|
|
|
// Context
|
|
|
|
adminApp.get("/context/:scope(global)",needsPermission("context.read"),context.get,apiUtil.errorHandler);
|
|
|
|
adminApp.get("/context/:scope(global)/*",needsPermission("context.read"),context.get,apiUtil.errorHandler);
|
|
|
|
adminApp.get("/context/:scope(node|flow)/:id",needsPermission("context.read"),context.get,apiUtil.errorHandler);
|
|
|
|
adminApp.get("/context/:scope(node|flow)/:id/*",needsPermission("context.read"),context.get,apiUtil.errorHandler);
|
|
|
|
|
2018-11-12 18:04:22 +01:00
|
|
|
// adminApp.delete("/context/:scope(global)",needsPermission("context.write"),context.delete,apiUtil.errorHandler);
|
|
|
|
adminApp.delete("/context/:scope(global)/*",needsPermission("context.write"),context.delete,apiUtil.errorHandler);
|
|
|
|
// adminApp.delete("/context/:scope(node|flow)/:id",needsPermission("context.write"),context.delete,apiUtil.errorHandler);
|
|
|
|
adminApp.delete("/context/:scope(node|flow)/:id/*",needsPermission("context.write"),context.delete,apiUtil.errorHandler);
|
|
|
|
|
2020-07-31 16:26:21 +02:00
|
|
|
adminApp.get("/settings",needsPermission("settings.read"),info.runtimeSettings,apiUtil.errorHandler);
|
|
|
|
|
2020-12-10 17:01:55 +01:00
|
|
|
// Plugins
|
|
|
|
adminApp.get("/plugins", needsPermission("plugins.read"), plugins.getAll, apiUtil.errorHandler);
|
|
|
|
adminApp.get("/plugins/messages", needsPermission("plugins.read"), plugins.getCatalogs, apiUtil.errorHandler);
|
|
|
|
|
2022-03-28 19:49:56 +02:00
|
|
|
adminApp.get("/diagnostics", needsPermission("diagnostics.read"), diagnostics.getReport, apiUtil.errorHandler);
|
2022-03-24 17:00:45 +01:00
|
|
|
|
2017-08-22 23:26:29 +02:00
|
|
|
return adminApp;
|
|
|
|
}
|
|
|
|
}
|