Expose web server express application to plugins
parent
e99352e2ac
commit
9048942ce9
|
@ -66,6 +66,7 @@ The first and only argument to the plugin function is an object with the followi
|
||||||
| `logs` | An object with functions to get attachment URLs/files and manage log storage types |
|
| `logs` | An object with functions to get attachment URLs/files and manage log storage types |
|
||||||
| `hooks` | An object with functions to add *hooks* that are called at specific times, e.g. before a new thread is created |
|
| `hooks` | An object with functions to add *hooks* that are called at specific times, e.g. before a new thread is created |
|
||||||
| `formats` | An object with functions that allow you to replace the default functions used for formatting messages and logs |
|
| `formats` | An object with functions that allow you to replace the default functions used for formatting messages and logs |
|
||||||
|
| `webserver` | An [Express Application object](https://expressjs.com/en/api.html#app) that functions as the bot's web server |
|
||||||
|
|
||||||
See the auto-generated [Plugin API](plugin-api.md) page for details.
|
See the auto-generated [Plugin API](plugin-api.md) page for details.
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ const logs = require("./modules/logs");
|
||||||
const move = require("./modules/move");
|
const move = require("./modules/move");
|
||||||
const block = require("./modules/block");
|
const block = require("./modules/block");
|
||||||
const suspend = require("./modules/suspend");
|
const suspend = require("./modules/suspend");
|
||||||
const webserver = require("./modules/webserver");
|
const { plugin: webserver } = require("./modules/webserver");
|
||||||
const greeting = require("./modules/greeting");
|
const greeting = require("./modules/greeting");
|
||||||
const typingProxy = require("./modules/typingProxy");
|
const typingProxy = require("./modules/typingProxy");
|
||||||
const version = require("./modules/version");
|
const version = require("./modules/version");
|
||||||
|
|
|
@ -54,16 +54,19 @@ function serveAttachments(req, res) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = () => {
|
const server = express();
|
||||||
const server = express();
|
server.use(helmet());
|
||||||
server.use(helmet());
|
|
||||||
|
|
||||||
server.get("/logs/:threadId", serveLogs);
|
server.get("/logs/:threadId", serveLogs);
|
||||||
server.get("/logs/:attachmentId/:filename", serveAttachments);
|
server.get("/logs/:attachmentId/:filename", serveAttachments);
|
||||||
|
|
||||||
server.on("error", err => {
|
server.on("error", err => {
|
||||||
console.log("[WARN] Web server error:", err.message);
|
console.log("[WARN] Web server error:", err.message);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(config.port);
|
module.exports = {
|
||||||
|
server,
|
||||||
|
plugin() {
|
||||||
|
server.listen(config.port);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
const express = require("express");
|
||||||
const { CommandManager } = require("knub-command-manager");
|
const { CommandManager } = require("knub-command-manager");
|
||||||
const { Client } = require("eris");
|
const { Client } = require("eris");
|
||||||
const Knex = require("knex");
|
const Knex = require("knex");
|
||||||
|
@ -12,6 +13,7 @@ const Knex = require("knex");
|
||||||
* @property {PluginLogsAPI} logs
|
* @property {PluginLogsAPI} logs
|
||||||
* @property {PluginHooksAPI} hooks
|
* @property {PluginHooksAPI} hooks
|
||||||
* @property {FormattersExport} formats
|
* @property {FormattersExport} formats
|
||||||
|
* @property {express.Application} webserver
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,6 +3,7 @@ const logs = require("./data/logs");
|
||||||
const { beforeNewThread } = require("./hooks/beforeNewThread");
|
const { beforeNewThread } = require("./hooks/beforeNewThread");
|
||||||
const { afterThreadClose } = require("./hooks/afterThreadClose");
|
const { afterThreadClose } = require("./hooks/afterThreadClose");
|
||||||
const formats = require("./formatters");
|
const formats = require("./formatters");
|
||||||
|
const { server: webserver } = require("./modules/webserver");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
/**
|
/**
|
||||||
|
@ -40,6 +41,7 @@ module.exports = {
|
||||||
afterThreadClose,
|
afterThreadClose,
|
||||||
},
|
},
|
||||||
formats,
|
formats,
|
||||||
|
webserver,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue