-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
59 lines (46 loc) · 1.41 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
54
55
56
57
58
59
const dotenv = require(`dotenv`);
const fs = require(`fs`);
const express = require(`express`);
const bodyParser = require(`body-parser`);
const hbs = require(`hbs`);
const routes = require('./routes/routes.js');
const db = require('./models/db.js')
const mongoose = require(`mongoose`);
const path = require(`path`);
const multer = require(`multer`);
const app = express();
dotenv.config();
port = process.env.PORT;
// hostname = process.env.HOSTNAME;
hbs.registerPartials(__dirname + '/views/partials');
app.set('views', path.join(__dirname, 'views'));
app.set(`view engine`, `hbs`);
app.use(express.urlencoded({extended: true}));
app.use(express.static(`public`));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(`/`, routes);
app.use(function (req, res) {
var error = {
collectionType: "page",
route: "/"
}
res.render('error', error);
});
app.listen(port, () => {
db.connect();
console.log(`Server running at `);
console.log(`port ` + port);
});
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, '/public/images')
},
filename: (req, file, cb) => {
console.log(file);
cb(null, Date.now() + path.extname(file.originalname))
}
})
const upload = multer({storage: storage})
app.get("/profile-page", (req, res) => {
res.render("profile-page");
});