-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
62 lines (50 loc) · 1.57 KB
/
Copy pathapp.js
File metadata and controls
62 lines (50 loc) · 1.57 KB
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
import DesoApi from "./api.js";
import fs from "fs"
import path from 'path';
const deso = new DesoApi
import express from 'express'
const app = express()
const port = 3000
async function getuserinfo(request){
const result = await deso.getKey(request)
return result
}
app.get('*', (req, res) => {
const value = Promise.resolve(getuserinfo(req.originalUrl.substring(1))).then(result =>{
if(result){
/*
var dir = `./${req.originalUrl.substring(1)}`;
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
*/
const resp = Object.values(JSON.parse(result))
for (let i = 0; i < resp.length; i++) {
/*
fs.writeFile(`./${req.originalUrl.substring(1)}/${Object.keys(resp[i])[0]}`,`${Object.values(resp[i])[0]}`, function(err){
console.log("Saved")
}) */
if(Object.keys(resp[i])[0] == "index.html"){
res.setHeader("Content-Type", "text/html");
res.writeHead(200);
res.end(`${Object.values(resp[i])[0]}`);
}
}
}else{
res.sendFile(path.resolve() + `/error.html`)
}
})
/* try{
if(fs.existsSync(path.resolve() + `/${req.originalUrl.substring(1)}`)){
res.sendFile(path.resolve() + `/${req.originalUrl.substring(1)}/index.html`)
}else{
res.sendFile(path.resolve() + `/error.html`)
}
}catch(err){
res.sendFile("If you are expecting a website refresh the page.")
}
res.sendFile(path.resolve() + `/error.html`)*/
})
app.listen(port, () => {
console.log("Listening of this path")
})