-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
74 lines (54 loc) · 1.74 KB
/
app.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const http = require("http");
const path = require("path");
const hostname = "127.0.0.1";
const port = 3000;
const multer = require("multer");
const fileUpload = require("express-fileupload");
const morgan = require("morgan");
const helmet = require("helmet");
const session = require("express-session");
const FileStore = require("session-file-store")(session);
const cookieParser = require("cookie-parser");
const fs = require("fs");
const logger = morgan("tiny");
const express = require('express');
const es6Renderer = require("express-es6-template-engine");
const app = express();
app.use(logger);
app.use(helmet());
app.engine("html", es6Renderer);
app.set("views", "./views");
app.set("view engine", "html");
app.use(express.static(path.join(__dirname, "public")));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(
session({
// store: new FileStore(),
secret: "super cool",
resave: false,
saveUninitialized: true,
is_logged_in: false
})
);
const storage = multer.diskStorage({
destination: function(req, file, cb) {
cb(null, 'media/');
},
filename: function(req, file, cb) {
cb(null, file.fieldname + '-' + Date.now() + path.extname(file.originalname));
}
});
const server = http.createServer(app);
server.listen(port, hostname, () => {
console.log(`Server Running at http://${hostname}:${port}`)
});
// Controller Creator
const usersController = require("./routes/usersRoute");
const indexController = require("./routes/index");
const uploadController = require("./routes/contentRoute");
// Use Controllers
app.use("/uploads", uploadController);
app.use("/users", usersController);
app.use("/", indexController);