mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Allow module to provide resources and automatically expose them
This commit is contained in:
@@ -75,6 +75,8 @@ module.exports = {
|
||||
editorApp.get("/icons/:module/:icon",ui.icon);
|
||||
editorApp.get("/icons/:scope/:module/:icon",ui.icon);
|
||||
|
||||
editorApp.get(/^\/resources\/((?:@[^\/]+\/)?[^\/]+)\/(.+)$/,ui.moduleResource);
|
||||
|
||||
var theme = require("./theme");
|
||||
theme.init(settings, runtimeAPI);
|
||||
editorApp.use("/theme",theme.app());
|
||||
|
@@ -68,6 +68,28 @@ module.exports = {
|
||||
apiUtils.rejectHandler(req,res,err);
|
||||
})
|
||||
},
|
||||
|
||||
moduleResource: function(req, res) {
|
||||
let resourcePath = req.params[1];
|
||||
let opts = {
|
||||
user: req.user,
|
||||
module: req.params[0],
|
||||
path: resourcePath
|
||||
}
|
||||
runtimeAPI.nodes.getModuleResource(opts).then(function(data) {
|
||||
if (data) {
|
||||
var contentType = mime.getType(resourcePath);
|
||||
res.set("Content-Type", contentType);
|
||||
res.send(data);
|
||||
} else {
|
||||
res.status(404).end()
|
||||
}
|
||||
}).catch(function(err) {
|
||||
console.log(err.stack);
|
||||
apiUtils.rejectHandler(req,res,err);
|
||||
})
|
||||
},
|
||||
|
||||
editor: async function(req,res) {
|
||||
res.send(Mustache.render(editorTemplate,await theme.context()));
|
||||
},
|
||||
|
Reference in New Issue
Block a user