-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
49 lines (38 loc) · 1.24 KB
/
Copy pathserver.js
File metadata and controls
49 lines (38 loc) · 1.24 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
import dotEnv from 'dotenv';
dotEnv.config();
import express from 'express';
// import logger from 'morgan';
import path from 'path';
import cookieParser from 'cookie-parser';
import bodyParser from 'body-parser';
import passport from 'passport';
import LocalStrategy from './strategies/local';
import JWTStrategy from './strategies/jwt';
const PORT = process.env.PORT || 3001;
const app = express();
// Middlewares
app.use(express.json());
app.use(passport.initialize());
app.use(passport.session());
// app.use(logger('tiny'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
passport.use(LocalStrategy);
passport.use(JWTStrategy);
// import exampleRoutes from './routes/example';
// app.use('/api/examples', exampleRoutes(app));
import authRoutes from './routes/auth';
authRoutes(app);
// Serve up static assets (usually on heroku)
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
// Send every request to the React app
// Define any API routes before this runs
app.get("*", function(req, res) {
res.sendFile(path.join(__dirname, "./client/build/index.html"));
});
app.listen(PORT, function() {
console.log(`🌎 ==> API server now on port ${PORT}!`);
});