-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (36 loc) · 1.23 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require('dotenv').config();
const fs = require("fs");
const express = require('express');
const app = express();
const https = require('https');
const http = require('http');
const Telegraf = require('telegraf');
const mongoose = require("mongoose");
mongoose.connect(`mongodb://${process.env.DB_USER}:${process.env.DB_PASSWORD}@localhost:27017/${process.env.DB_NAME}`, { useNewUrlParser: true }).catch(function(err) {
console.log(err);
});
const bot = new Telegraf(process.env.TOKEN);
require('./responces')(bot);
require('./models/Request');
bot.use(require('./middlewares/logger'));
app.use(require('./routes'));
app.use(bot.webhookCallback(`/${process.env.TOKEN}`));
/// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// Listening HTTPS
const httpsServer = https.createServer({
key: fs.readFileSync('./server.key'),
cert: fs.readFileSync('./server.pem')
}, app);
httpsServer.listen(process.env.PORT, () => {
console.log("server starting on port : " + process.env.PORT)
});
// Listening HTTP
const httpServer = http.createServer(app);
httpServer.listen(80, () => {
console.log("server starting on port : " + 80)
});