-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
68 lines (62 loc) · 2.27 KB
/
app.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
const http = require('http');
const fs = require('fs');
const url = require('url');
const hostname = '127.0.0.1';
const port = 3000;
var static = require('node-static');
var fileServer = new static.Server('./dist', {indexFile: 'index.html'});
const server = http.createServer((req, res) => {
const parsedUrl = url.parse(req.url);
if (parsedUrl.pathname.includes('Aura_27')) {
fs.readFile('./dist/assets/Aura_27.dae', function (err, data) {
if (err) {
res.statusCode = 500;
res.end(`Error getting the file: ${err}.`);
} else {
res.setHeader('Content-type', 'application/xml');
res.end(data);
}
});
} else if (parsedUrl.pathname.includes('tex_01.psd')) {
let pathname = 'NOT_FOUND';
if (parsedUrl.pathname.includes('tex_01.psd.001')) {
pathname = './dist/assets/tex_01.psd.001.jpg';
} else {
pathname = './dist/assets/tex_01.psd.004.jpg';
}
fs.readFile(pathname, function (err, data) {
if (err) {
res.statusCode = 500;
res.end(`Error getting the file: ${err}.`);
} else {
res.setHeader('Content-type', 'image/jpeg');
res.end(data);
}
});
} else if (parsedUrl.pathname.includes('foil_')) {
let pathname = 'NOT_FOUND';
if (parsedUrl.pathname.includes('gold_ramp')) {
pathname = './dist/assets/foil_n_gold_ramp.pn.000.png';
} else if (parsedUrl.pathname.includes('silver_ramp')) {
pathname = './dist/assets/foil_silver_ramp.pn.000.png';
} else {
pathname = './dist/assets/foil_n.pn.001.png';
}
fs.readFile(pathname, function (err, data) {
if (err) {
res.statusCode = 500;
res.end(`Error getting the file: ${err}.`);
} else {
res.setHeader('Content-type', 'image/png');
res.end(data);
}
});
} else {
req.addListener('end', function () {
fileServer.serve(req, res);
}).resume();
}
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});