[refactor] Move server logic to /server
This commit is contained in:
parent
968f1a8e1e
commit
1199d4e20d
4
bot.js
4
bot.js
|
@ -1,8 +1,8 @@
|
|||
const Telegraf = require("telegraf");
|
||||
const Sequelize = require("sequelize");
|
||||
|
||||
const main = require("./bot");
|
||||
const config = require("./config");
|
||||
const main = require("./bot/index");
|
||||
const { bot: config } = require("./config");
|
||||
const db = require("./data")(Sequelize, config);
|
||||
const bot = new Telegraf(config.botApiKey);
|
||||
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
module.exports = {
|
||||
// Create a new bot by messaging @BotFather and follow the instructions
|
||||
// Replace the key by the actual token recieved from BotFather
|
||||
botApiKey: "key",
|
||||
|
||||
bot: {
|
||||
// Create a new bot by messaging @BotFather and follow the instructions
|
||||
// Replace the key by the actual token recieved from BotFather
|
||||
botApiKey: "bot_api_key",
|
||||
},
|
||||
server: {
|
||||
port: 2000
|
||||
},
|
||||
// Connection information for database
|
||||
"sequelize": {
|
||||
sequelize: {
|
||||
database: "git-alerts-bot",
|
||||
username: "git-bot",
|
||||
password: "hopefully_a_secure_password",
|
||||
|
@ -12,7 +16,7 @@ module.exports = {
|
|||
host: "localhost",
|
||||
dialect: "sqlite",
|
||||
// SQLite only
|
||||
storage: "./store/git-alerts-bot.sqlite"
|
||||
}
|
||||
storage: "./store/git-alerts-bot.sqlite",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
19
server.js
19
server.js
|
@ -1,12 +1,19 @@
|
|||
const express = require("express");
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
const main = require("./server/index");
|
||||
const convert = require("./util/convert");
|
||||
const { server: config } = require("./config");
|
||||
const PORT = config.server.port;
|
||||
|
||||
app.get("/webhook/:provider", (req) => {
|
||||
const app = express();
|
||||
|
||||
const strategy = req.params.provider;
|
||||
const eventType = convert.getEvent[strategy](req.body);
|
||||
app.use(express.json());
|
||||
app.use((req, res, next) => {
|
||||
|
||||
req.convert = convert;
|
||||
next();
|
||||
|
||||
});
|
||||
app.listen(2000, () => console.log("Listening on port 2000"));
|
||||
|
||||
main(app);
|
||||
|
||||
app.listen(PORT, () => console.log("Listening on port", PORT));
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
module.exports = app => {
|
||||
|
||||
app.get("/webhook/:provider", (req, res) => {
|
||||
|
||||
const strategy = req.params.provider;
|
||||
const eventType = req.convert.getEvent[strategy](req.body);
|
||||
|
||||
});
|
||||
|
||||
};
|
Loading…
Reference in New Issue