-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (35 loc) · 1.16 KB
/
index.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
const Express = require("express");
const multer = require("multer");
const bodyParser = require("body-parser");
const path = require("path");
const serveIndex = require("serve-index");
const internalIp = require('internal-ip');
const app = Express();
const port = 80;
app.use(Express.static(path.join(__dirname, "public")));
app.use(bodyParser.json());
var Storage = multer.diskStorage({
destination: function (req, file, callback) {
callback(null, "./images");
},
filename: function (req, file, callback) {
callback(null, file.fieldname + "_" + Date.now() + "_" + file.originalname); //file.fieldname + "_" + Date.now() + "_" + file.originalname
}
});
var upload = multer({
storage: Storage
}).array("imgUploader", 3);
app.get("/", (req, res) => {
res.render("main.ejs");
});
app.use("/images", serveIndex(__dirname + "/images"));
app.use("/images", Express.static(__dirname + "\\images"));
app.post("/api/Upload", (req, res) => {
upload(req, res, err => {
if (err) {
return res.end("Błąd: " + err);
}
return res.render("sent.ejs");
});
});
app.listen(port, console.log(`address to connect to: ${internalIp.v4.sync()}:${port}`));