forked from eJayYoung/vux-uploader-component
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
32 lines (27 loc) · 947 Bytes
/
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
const express = require('express');
const bodyParser = require('body-parser');
const multer = require('multer'); // v1.0.5
const http = require('http');
const app = express();
const upload = multer();
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
const allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
};
app.use(allowCrossDomain);
app.post('/upload', upload.any(), function(req, res) {
if (req.files.length > 0 && req.files.length <= 5) {
res.send({
data: req.files,
code: 200,
msg: null,
});
}
});
http.createServer(app).listen(9090, function() {
console.log('Express Server listening on port 9090');
});