summaryrefslogtreecommitdiffstats
path: root/backend/index.ts
blob: 140e7b986b6d6059b9190868c07625fdf6ee0eaa (plain) (blame)
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
import express from "express";
import cors from "cors";
import * as dotenv from "dotenv";

// import abc from "./modules/dummy";
// abc();

// const global = { stop: false };

dotenv.config();
const app = express();
const PORT = 5000;


app.use(express.json());
app.use(cors());
app.use("/", express.static("../dist"));

const longpoll = require("express-longpoll")(app);
longpoll.create("/poll", cors());
var data = { text: "Some data" };

app.post("/send", (req, res) => {
    console.log(JSON.stringify(req));
    longpoll.publish("/poll", req.body)
    res.send("OK");
});

app.listen(PORT, () => {
  console.log(`[server]: Server is running at https://localhost:${PORT}`);
});
// longpoll.publish("/poll", data);

setInterval(function () { 
    longpoll.publish("/poll", data);
}, 1000);