-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
27 lines (21 loc) · 893 Bytes
/
app.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
// подключение express
const express = require("express");
const cors = require('cors');
// создаем объект приложения
const app = express();
const PORT = process.env.PORT || 3000;
const bot = require('./bot-modules/bot-interface.js');
app.use(cors());
app.use(express.json()); // for parsing application/json
app.use(express.static("client"));
// определяем обработчик для маршрута пост запроса
app.post("/request-to-bot", (request, response) => {
if(!request.body) return response.sendStatus(400);
const botAnswer = new Promise( resolve => resolve(bot(request.body.request)) );
botAnswer
.then(answer => response.send( answer ));
});
// начинаем прослушивать подключения
app.listen(PORT, () => {
console.log(`server has been started on port: ${PORT}`);
});