[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 Telegraf = require("telegraf");
|
||||||
const Sequelize = require("sequelize");
|
const Sequelize = require("sequelize");
|
||||||
|
|
||||||
const main = require("./bot");
|
const main = require("./bot/index");
|
||||||
const config = require("./config");
|
const { bot: config } = require("./config");
|
||||||
const db = require("./data")(Sequelize, config);
|
const db = require("./data")(Sequelize, config);
|
||||||
const bot = new Telegraf(config.botApiKey);
|
const bot = new Telegraf(config.botApiKey);
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// Create a new bot by messaging @BotFather and follow the instructions
|
bot: {
|
||||||
// Replace the key by the actual token recieved from BotFather
|
// Create a new bot by messaging @BotFather and follow the instructions
|
||||||
botApiKey: "key",
|
// Replace the key by the actual token recieved from BotFather
|
||||||
|
botApiKey: "bot_api_key",
|
||||||
|
},
|
||||||
|
server: {
|
||||||
|
port: 2000
|
||||||
|
},
|
||||||
// Connection information for database
|
// Connection information for database
|
||||||
"sequelize": {
|
sequelize: {
|
||||||
database: "git-alerts-bot",
|
database: "git-alerts-bot",
|
||||||
username: "git-bot",
|
username: "git-bot",
|
||||||
password: "hopefully_a_secure_password",
|
password: "hopefully_a_secure_password",
|
||||||
|
@ -12,7 +16,7 @@ module.exports = {
|
||||||
host: "localhost",
|
host: "localhost",
|
||||||
dialect: "sqlite",
|
dialect: "sqlite",
|
||||||
// SQLite only
|
// 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 express = require("express");
|
||||||
const app = express();
|
const main = require("./server/index");
|
||||||
app.use(express.json());
|
|
||||||
const convert = require("./util/convert");
|
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;
|
app.use(express.json());
|
||||||
const eventType = convert.getEvent[strategy](req.body);
|
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