2014-11-04 12:34:49 +01:00
|
|
|
/**
|
|
|
|
* Copyright 2014 IBM Corp.
|
|
|
|
*
|
|
|
|
* 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 util = require('util');
|
|
|
|
|
|
|
|
var ui = require("./ui");
|
|
|
|
var nodes = require("./nodes");
|
2014-11-06 11:59:34 +01:00
|
|
|
var plugins = require("./plugins");
|
2014-11-04 12:34:49 +01:00
|
|
|
var flows = require("./flows");
|
|
|
|
var library = require("./library");
|
|
|
|
|
|
|
|
var settings = require("../settings");
|
|
|
|
|
|
|
|
var errorHandler = function(err,req,res,next) {
|
|
|
|
//TODO: standardize json response
|
|
|
|
res.send(400,err.toString());
|
2014-11-06 11:00:25 +01:00
|
|
|
};
|
2014-11-04 12:34:49 +01:00
|
|
|
|
|
|
|
function init(adminApp) {
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-11-04 12:34:49 +01:00
|
|
|
adminApp.use(express.json());
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-11-05 23:41:05 +01:00
|
|
|
library.init(adminApp);
|
|
|
|
|
2014-11-04 12:34:49 +01:00
|
|
|
// Editor
|
|
|
|
if (!settings.disableEditor) {
|
|
|
|
adminApp.get("/",ui.ensureSlash);
|
|
|
|
adminApp.get("/icons/:icon",ui.icon);
|
|
|
|
adminApp.get("/settings",ui.settings);
|
|
|
|
adminApp.use("/",ui.editor);
|
|
|
|
}
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-11-04 12:34:49 +01:00
|
|
|
// Flows
|
|
|
|
adminApp.get("/flows",flows.get);
|
|
|
|
adminApp.post("/flows",flows.post);
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-11-04 12:34:49 +01:00
|
|
|
// Nodes
|
|
|
|
adminApp.get("/nodes",nodes.getAll);
|
|
|
|
adminApp.post("/nodes",nodes.post);
|
|
|
|
|
|
|
|
adminApp.get("/nodes/:id",nodes.get);
|
|
|
|
adminApp.put("/nodes/:id",nodes.put);
|
|
|
|
adminApp.delete("/nodes/:id",nodes.delete);
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-11-06 11:59:34 +01:00
|
|
|
// Plugins
|
|
|
|
adminApp.get("/plugins",plugins.getAll);
|
|
|
|
adminApp.get("/plugins/:id",plugins.get);
|
2014-11-06 11:00:25 +01:00
|
|
|
|
2014-11-04 12:34:49 +01:00
|
|
|
// Library
|
|
|
|
adminApp.post(new RegExp("/library/flows\/(.*)"),library.post);
|
|
|
|
adminApp.get("/library/flows",library.getAll);
|
|
|
|
adminApp.get(new RegExp("/library/flows\/(.*)"),library.get);
|
2014-11-06 11:00:25 +01:00
|
|
|
|
|
|
|
|
2014-11-04 18:05:29 +01:00
|
|
|
// Error Handler
|
2014-11-04 12:34:49 +01:00
|
|
|
adminApp.use(errorHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
init: init
|
2014-11-06 11:00:25 +01:00
|
|
|
};
|