-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.devServer.js
More file actions
82 lines (73 loc) · 2.14 KB
/
webpack.devServer.js
File metadata and controls
82 lines (73 loc) · 2.14 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
const dirs = require('./mocks/mock_dirs');
const dir = require('./mocks/mock_dir');
module.exports = {
open: false,
contentBase: path.join(__dirname, 'public/'),
compress: true,
watchContentBase: true,
publicPath: '/',
quiet: true,
host: '0.0.0.0',
overlay: false,
historyApiFallback: {
// Paths with dots should still use the history fallback.
// See https://github.com/facebook/create-react-app/issues/387.
disableDotRule: true,
},
port: 3000,
hot: false,
hotOnly: false,
before: (app, server) => {
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// get files
app.all('/resources/api/directory/metadata', (req, res) => {
const path = req.body.path;
if (path === '/') res.json(dirs);
else res.json(dir);
});
// create folder
app.all('/resources/api/directory/create', (req, res) => {
res.json({ code: 'OK' });
});
// copy
app.all('/resources/api/resource/copy', (req, res) => {
res.json({ code: 'OK' });
console.log(req.body);
});
// move
app.all('/resources/api/resource/move', (req, res) => {
res.json({ code: 'OK' });
console.log(req.body);
});
// delete
app.all('/resources/api/resource/delete', (req, res) => {
res.json({ code: 'OK' });
console.log(req.body);
});
// upload
app.all('/resources/api/resource/upload', (req, res) => {
res.json({ code: 'OK' });
console.log(req.body);
});
// archive
app.all('/resources/api/resource/zip', (req, res) => {
res.json({ code: 'OK' });
console.log(req.body);
});
// get file
app.use('/resources/upload/', (req, res) => {
const ext = /[.]/.exec(req.originalUrl) ? /[^.]+$/.exec(req.originalUrl) : undefined;
if (ext[0] === 'jpg') {
res.sendfile('./mocks/sample.jpg');
} else if (ext[0] === 'png') {
res.sendfile('./mocks/sample.png');
} else if (ext[0] === 'pdf') {
res.sendfile('./mocks/sample.pdf');
}
});
},
};