-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
52 lines (43 loc) · 1.21 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
const { PORT, NODE_ENV } = process.env;
if(!PORT){
throw new Error('PORT not defined');
}
if(!NODE_ENV){
throw new Error('NODE_ENV not defined');
}
/*=====================================
Init
=======================================*/
/* ----- Dependencies ----- */
const path = require("path");
const express = require("express");
const app = express();
const cors = require("cors");
const bodyParser = require("body-parser");
const graphql = require(path.resolve(__dirname, "graphql"));
/*=====================================
Setup
=======================================*/
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
graphql(app);
/**
* declare the location of the frontend app to be a static directory
* to be tried after all other routes
*/
app.get("/", (req, res) => {
res.json({ message: "Custom shirts API" });
})
app.use(function(err, req, res, next) {
res.status(res.statusCode || 500).json({ message: err.message });
});
app.use(function(req, res, next) {
res.status(404).json({ message: "Not found" });
});
if (NODE_ENV !== "test") {
app.listen(PORT, function() {
console.log(`App listenting on port ${PORT}`);
});
}
module.exports = app;