forked from ColinGeukes/ConversationalAgentTaskClarity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
76 lines (64 loc) · 2.13 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const fs = require('fs');
const credentials = {
key: fs.readFileSync('private.key', 'utf8'),
cert: fs.readFileSync('sander_gielisse_me.cer', 'utf8'),
ca: [
fs.readFileSync('Sectigo_RSA_Domain_Validation_Secure_Server_CA.crt', 'utf8'),
fs.readFileSync('USERTrust_RSA_Certification_Authority.crt', 'utf8'),
]
};
const express = require('express');
const app = express()
const path = require('path');
const bodyParser = require('body-parser');
// allow access to public folder
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
files = {
"0": "toloka/index.html",
"1": "toloka/script.js"
}
app.get('/request_file', (req, res) => {
var filename = files[req.query.filename]
var mime;
if (filename.endsWith(".js")) {
mime = "application/javascript";
} else if (filename.endsWith(".html")){
mime = "text/html";
}
var identifier = req.query.identifier
// lookup the file in the public dir
var filepath = path.join(__dirname, '/public/' + filename)
console.log("requesting file... ", filepath, ' with id ', identifier, ' and mime ', mime)
fs.readFile(filepath, "utf8", function(err, data) {
data = data.replace(/%IDENTIFIER%/g, identifier);
res.contentType(mime);
res.send(data);
});
})
app.post('/confirm_answers', function(req, res) {
var submission = req.body
var json = JSON.stringify(submission);
console.log("BODY", json)
// save this information
var id = submission.id
fs.writeFile('./submissions/' + id + '.json', json, 'utf8', function(err){
console.log("ERROR " + err);
});
console.log("Submission saved!");
res.sendStatus(200)
});
app.get('/isdone', (req, res) => {
var id = req.query.id;
var file = './submissions/' + id + '.json'
var r = "false";
if (fs.existsSync(file)){
r = "true";
}
res.setHeader('Access-Control-Allow-Origin', 'https://iframe-toloka.com');
res.send(r)
})
const https = require('https');
var httpsServer = https.createServer(credentials, app);
httpsServer.listen(443);