-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (29 loc) · 1.08 KB
/
index.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
require("dotenv").config();
const graphqlLogger = require("./utils/graphql_logger");
const errorHandler = require("./utils/error_handler");
const authenticate = require("./utils/authenticate");
const ratelimiter = require("./utils/rate_limiter");
const { graphqlHTTP } = require("express-graphql");
const express = require("express");
const morgan = require("morgan");
const helmet = require("helmet");
const cors = require("cors");
const app = express();
const isProd = process.env.NODE_ENV === "production";
// Middlewares
app.use(morgan(isProd ? "combined" : "dev"));
app.use(helmet());
app.use(cors());
app.use(ratelimiter);
app.use(express.json());
app.use(express.static(__dirname + "/public"));
// Routes
app.use("/", require("./routes/home/home.controller"));
app.use(authenticate);
app.use("/plants", require("./routes/plants/plants.controller"));
app.use("/graphql", graphqlLogger, graphqlHTTP({ schema: require("./graphql/schema") }));
// Errors
app.use(errorHandler);
// Server
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => console.log("Server listening on port " + PORT));