forked from ayushnanda14/School-Auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (46 loc) · 1.29 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
const express = require('express');
const mysql = require('mysql');
const path = require('path');
const dotenv = require('dotenv');
const router = require('./routes/pages');
const authRouter = require('./routes/auth');
const googleRouter = require('./routes/google');
const cookieParser = require('cookie-parser');
const passport = require('passport');
const cookieSession = require('cookie-session');
require('./passport-setup');
dotenv.config({ path: './.env' });
const app = express();
const db = mysql.createConnection({
host: process.env.DB_HOST, //ip address of server
user: process.env.DB_USER,
password: process.env.DB_PWD,
database: process.env.DB,
});
const publicDir = path.join(__dirname, './public');
app.use(express.static(publicDir));
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(cookieParser());
app.use(
cookieSession({
name: 'school-session',
keys: ['key1', 'key2'],
})
);
app.use(passport.initialize());
app.use(passport.session());
app.set('view engine', 'hbs');
app.use('/', router);
app.use('/auth', authRouter);
app.use('/google', googleRouter);
db.connect((err) => {
if (err) {
console.log(err);
} else {
console.log('MYSQL Connected!');
}
});
app.listen(5000, () => {
console.log('Server started on port 5000');
});