-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
61 lines (56 loc) · 1.61 KB
/
main.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
const express = require('express');
const nunjucks = require('nunjucks');
const path = require('path');
const request = require('request');
const Datastore = require('nedb');
const fs = require('fs');
const app = express();
htmldb= new Datastore({filename:path.join(__dirname, 'data/dbs/html.db'), autoload: true})
scratchdb= new Datastore({filename:path.join(__dirname, 'data/dbs/scratch.db'), autoload: true})
userdb= new Datastore({filename:path.join(__dirname, 'data/dbs/users.db'), autoload: true})
app.use(express.static(path.join(__dirname, 'data')))
nunjucks.configure(path.join('data', 'html'), {
autoescape: true,
express: app
});
app.get('/', (req,res) => {
htmldb.find({}, function(err,docs) {
var html = docs;
scratchdb.find({}, (err,docs) =>{
var scratch = docs;
userdb.find({}, (err,docs) => {
var users=docs
res.render("home.html", {html: html, scratch: scratch, users: users});
})
});
});
});
app.get('/scratch', (req,res) => {
let id = req.query.id;
res.render("scratchgame.html", {'id': id})
})
app.get('/html', (req,res) => {
htmldb.find({id: req.query.id}, (err,docs) => {
res.render("htmlgame.html", {link0: docs[0].link0})
})
})
app.get('/list', (req,res) => {
var dir = req.query.dir;
console.log(dir);
fs.readdir(path.join(__dirname,dir), (err,files) => {
console.log(files);
console.log(err);
if (err) {
res.send(err);
} else {
res.send(files);
}
})
})
app.get("*", (req,res) => {
res.sendFile(path.join(__dirname,"data","html", "/error.html"))
})
const server = app.listen(process.env.PORT || 8080, () =>{
console.log("Running")
console.log(server.address());
})