-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (39 loc) · 1.34 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
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const session = require('express-session')
const db = require('./models')
const SequelizeStore = require('connect-session-sequelize')(session.Store);
const store = new SequelizeStore({ db: db.sequelize })
store.sync()
const checkAuth = require("./checkAuth")
const indexRouter = require('./routes/index');
const usersRouter = require('./routes/users');
const plantsRouter = require('./routes/plants');
const { application } = require('express');
const app = express();
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(
session({
secret: 'secret', // used to sign the cookie
resave: false, // update session even w/ no changes
saveUninitialized: true, // always create a session
cookie: {
secure: false, // true: only accept https req's
maxAge: 2592000, // time in seconds
},
store: store,
})
);
app.use(express.static(path.join(__dirname, 'client/build')));
// app.use('/', indexRouter);
app.use('/api/v1/users', usersRouter);
app.use('/api/v1/plants', checkAuth, plantsRouter);
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'client/build/index.html'));
});
module.exports = app;