-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
56 lines (43 loc) · 1.52 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
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const cors = require('cors');
const request = require('request');
const dotenv = require('dotenv').config();
const app = express();
// Enable CORS
app.use(cors());
// Serve static files from the React app
app.use(express.static(path.join(__dirname, 'client/build')));
// app.use(express.static(path.join(__dirname, './')));
const usersRoute = require("./routes/users");
const authRoute = require("./routes/auth");
const gardensRoute = require("./routes/gardens");
const plantsRoute = require("./routes/plants");
const weatherRoute = require("./routes/weather");
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
next();
});
app.use("/api/users", usersRoute);
app.use("/api/gardens", gardensRoute);
app.use("/api/plants", plantsRoute);
app.use("/api/auth", authRoute);
app.use("/api/weather", weatherRoute);
/* For Deploying */
// The "catchall" handler: for any request that doesn't
// match one above, send back React's index.html file.
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname+'/client/build/index.html'));
});
app.set('port', (process.env.PORT || 3001));
app.listen(app.get('port'), () => {
console.log(`Listening on ${app.get('port')}`);
});
module.exports = app;