-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbackend.js
More file actions
86 lines (72 loc) · 2.08 KB
/
Copy pathbackend.js
File metadata and controls
86 lines (72 loc) · 2.08 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const express = require('express');
const mongoose = require('mongoose');
const apiRouter = require('./router/apiRouter');
const bodyParser = require('body-parser');
const session = require('express-session');
const cors = require('cors');
// var FacebookStrategy = require('passport-facebook').Strategy;
const passport=require("passport")
// const passportfb=require("passport-facebook").Strategy
const userModel = require("./model/userModel");
const domain =require("./config/domain")
let backend = express();
backend.use(cors({
credentials: true,
origin: true
}))
backend.enable('trust proxy');
backend.use(session({
secret: 'Nguoi yeu dau hoi~ em mai la mat troiiii',
resave: false,
proxy: true,
saveUninitialized: false,
cookie: {
secure: true,
httpOnly: false,
maxAge: 1000 * 60 * 60 * 24 * 7
}
}))
backend.use(bodyParser.urlencoded({ extended: false, limit:'10mb' }));
backend.use(bodyParser.json({limit: '10mb'}));
backend.use(passport.initialize());
backend.use(passport.session());
backend.use((req, res, next) => {
next();
})
backend.use('/api', apiRouter);
var authFB = require('./router/auth.fb')(passport);
backend.use('/api', authFB);
let host = 'mongodb://FoodyHoLa:Hola123@ds243212.mlab.com:43212/foodyhoalac';
// let host = 'mongodb://localhost/Project';
mongoose.connect(host, function (err) {
if (err) {
console.log(err);
} else {
console.log("mongodb success!")
}
});
//config https
var fs = require('fs');
var https = require('https');
var options =
{
key: fs.readFileSync('./privkey.pem'),
cert: fs.readFileSync('./fullchain.pem')
};
var server = https.createServer(options, backend);
server.listen(process.env.PORT || 8080, err => {
if (err) {
console.error(err);
} else {
console.log("Server is listening with localhost 8080");
}
})
// passport.serializeUser((user,done)=>{
// done(null,user.id)
// })
// passport.deserializeUser((id,done)=>{
// userModel.findOne({facebookID:id},(err,user)=>{
// done(null,user);
// })
// })
//Demo Github