-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
53 lines (42 loc) · 1.36 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
53
const fileUpload = require('express-fileupload');
const express = require("express");
const path = require('path');
module.exports = () => {
const app = express();
app.use(fileUpload());
app.use('/static', express.static('public'));
app.get('/',(req,res,next) => { //here just add next parameter
res.sendFile(
path.resolve( __dirname, "index.html" )
)
// next();
})
app.get("/techterns", (req, res) => {
res.json(["Cristina", "Jordan","Karina","Lysander","Victor"]);
});
app.post('/upload', function(req, res) {
try {
if (!req.files || Object.keys(req.files).length === 0) {
return res.status(400).send('No files were uploaded.');
} else {
// The name of the input field (i.e. "sampleFile") is used to retrieve the uploaded file
let imageFile = req.files.imageFile;
let uploadPath = __dirname + `/public/input/image.png`;
// Use the mv() method to place the file somewhere on your server
imageFile.mv(uploadPath, function(err) {
if (err)
return res.status(500).send(err);
res.send({status: true, message: 'File uploaded!'});
});
}
} catch(err) {
res.status(500).send(err);
}
});
app.get("*", (req, res) => {
res.sendFile(
path.resolve( __dirname, "index.html" )
)
});
return app;
}