forked from algorithm-visualizer/algorithm-visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend.js
More file actions
42 lines (38 loc) · 1.13 KB
/
backend.js
File metadata and controls
42 lines (38 loc) · 1.13 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
const {
__DEV__,
backendBuildPath,
} = require('../environment');
if (__DEV__) {
const webpack = require('webpack');
const webpackConfig = require('../webpack.backend.config.js');
const compiler = webpack(webpackConfig);
let backend = null;
let lastHash = null;
compiler.watch({
watchOptions: {
ignored: /public/,
},
}, (err, stats) => {
if (err) {
lastHash = null;
compiler.purgeInputFileSystem();
console.error(err);
} else if (stats.hash !== lastHash) {
lastHash = stats.hash;
console.info(stats.toString({
cached: false,
colors: true,
}));
delete require.cache[require.resolve(backendBuildPath)];
backend = require(backendBuildPath).default;
}
});
const backendWrapper = (req, res, next) => backend(req, res, next);
backendWrapper.getHierarchy = () => backend.hierarchy;
module.exports = backendWrapper;
} else {
const backend = require(backendBuildPath).default;
const backendWrapper = (req, res, next) => backend(req, res, next);
backendWrapper.getHierarchy = () => backend.hierarchy;
module.exports = backendWrapper;
}