-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuserRoute.js
54 lines (34 loc) · 1.36 KB
/
userRoute.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
const express = require('express');
const user_route= express();
const bodyParser = require('body-parser');
const session = require('express-session');
const { SESSION_SECRET } = process.env;
user_route.use(session({secret:SESSION_SECRET}));
user_route.use(bodyParser.json());
user_route.use(bodyParser.urlencoded({extended:true}));
user_route.set('view engine','ejs');
user_route.set('views','./views');
user_route.use(express.static('pubilc'));
const path = require('path');
const multer = require('multer');
const storage = multer.diskStorage({
destination:function(req, file, cb) {
cb(null, path.join(__dirname,'../public/images'));
},
filename:function(req, file, cb){
const name = Date.now()+'-'+file.originalname;
cb(null,name);
}
});
const upload = multer({storage:storage});
const userController = require('../controllers/userController');
user_route.get('/register', userController.registerLoad);
user_route.post('/register', upload.single('image'), userController.register);
user_route.get('/', userController.loadlogin);
user_route.post('/', userController.login);
user_route.get('/logout', userController.logout);
user_route.get('/dashboard', userController.loadDashboard);
user_route.get('*', function(req, res) {
res.redirect('/');
});
module.exports= user_route;