-
Notifications
You must be signed in to change notification settings - Fork 11
/
server.js
52 lines (41 loc) · 1.25 KB
/
server.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
const express = require("express");
const webpack = require("webpack");
const webpackDevMiddleware = require("webpack-dev-middleware");
const app = express();
const config = require("./webpack.config.js");
const compiler = webpack(config);
const PORT = 3000
const crypto = require("crypto");
const fs = require("fs");
const path = require("path")
const key = Buffer.from(
"6b65796b65796b65796b65796b65796b65796b65796b6579",
"hex"
).toString("utf8");
app.get("/*.glb$/", function (req, res) {
console.log("123");
//先固定路径为例
const filepath = path.join(__dirname, "./public/models/Xbot.glb");
console.log("filepath: ", filepath);
if (!fs.existsSync(filepath)) {
res.status(404).send("");
} else {
const cipher = crypto.createCipheriv(
"aes-192-ctr",
key,
Buffer.alloc(16, 0)
);
const buf = Buffer.from(filepath);
fs.createReadStream(buf).pipe(cipher).pipe(res);
}
});
app.use(
webpackDevMiddleware(compiler, {
publicPath: config.output.publicPath,
})
);
// app.use(express.static("./static"));
app.listen(PORT, function () {
console.log(`app listening on port ${PORT}!\n`);
console.log(`open:http://127.0.0.1:${PORT}`);
});