-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (37 loc) · 1.04 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
const express = require('express')
const bodyparser = require('body-parser')
const cors = require('cors')
const fs = require('fs')
var datetime = require('node-datetime')
const app = express();
app.use(bodyparser.json())
app.use(bodyparser.urlencoded({extended: true}))
app.get('/', function(req, res) {
res.send("Cannot GET /")
})
app.post('/createNewRoom', function(req, res) {
try {
if(!fs.existsSync(`transcript/${id}`)) {
fs.mkdirSync(`transcript/${id}`);
}
}
catch {
res.send({success: 0});
}
res.send({success: 1});
})
app.post('/writeMessage', function(req, res) {
const result = req.body;
var dt = datetime.create();
var formatted = dt.format("d-m-Y H:M:S");
const finalResult = `${formatted} [${result.name}]: ${result.passage}`
fs.appendFile(`transcript/${id}/${result.id}.txt`, finalResult, err => {
if (err) {
console.log(err);
}
})
res.send({success: 1});
})
app.listen(80, () => {
console.log("Listening on port 80")
})