forked from electronicarts/ShaderToHuman
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
58 lines (47 loc) · 1.41 KB
/
server.js
File metadata and controls
58 lines (47 loc) · 1.41 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
const express = require('express');
const path = require('path');
const app = express();
const utils = require('./docs/utils') // utils.js
const port = 3000;
const hostname = '127.0.0.1';
const index = "index.html"
// Serve static files from the 'root' directory
app.use(express.static(__dirname));
app.use(express.static(path.join(__dirname, "docs")));
// Return home page
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, "docs", index));
});
app.get('/listfiles', (req, res) => {
const hlslfiles = utils.search();
res.send(hlslfiles)
});
app.get('/zip', (req, res) => {
var type = req.query.type;
if (type === "undefined") {
type = 'hlsl';
}
const hlslfiles = utils.search();
// Converts HLSL files to given type and then zips the results
utils.zipFiles(hlslfiles, type)
.then(buffer => {
res.set('Content-Type', 'application/zip');
res.set('Content-Disposition', 'attachment; filename="shaders.zip"');
res.send(buffer);
});
});
app.get('/preprocess', (req, res) => {
const file = req.query.file;
utils.preprocess(file).then(result => {
res.send(result)
});
});
app.get('/about', (req, res) => {
res.send('About page');
});
app.use((req, res, next) => {
res.status(404).send("Sorry can't find that!")
})
app.listen(port, () => {
console.log(`Server listening on http://${hostname}:${port}/`);
});