-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackend.js
51 lines (40 loc) · 1.1 KB
/
backend.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
const env = process.env.NODE_ENV;
const meow = require("meow");
let args = meow("", {
flags: {
port: {
type: "string",
default: "4000"
}
}
});
const conf = {
port: parseInt(args.flags.port)
};
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const http = require("http").createServer(app);
if (env != "production") {
const webpack = require("webpack");
const wpConf = require("./webpack.config");
const webpackDevMiddleware = require("webpack-dev-middleware");
const wpCompiler = webpack(wpConf);
app.use(
webpackDevMiddleware(wpCompiler, {
publicPath: wpConf.output.publicPath
})
);
}
app.post("/update", bodyParser.text(), (req, res) => {
require("fs").writeFileSync("outputtest/output.js", req.body);
res.sendStatus(200);
});
app.post("/getfile", require("multer")().any(), (req, res) => {
res.set("Content-Type", "text/plain");
res.send(req.files[0].buffer.toString());
});
app.use(express.static("./dist"));
http.listen(conf.port, () => {
console.log("Listening on port %s", conf.port);
});