-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
40 lines (35 loc) · 1 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
import express from 'express';
import bodyParser from 'body-parser';
import graphqlHTTP from 'express-graphql';
import Routes from './config/Routes';
//DB
import ToDo from './model/todo';
//Graph
import schema from './graphql/Schema/Schema';
import { graphql } from 'graphql';
const app = express();
app.use(bodyParser.urlencoded({ extended: true }))
//SECTION Render static html
app.get(Routes.base, (req, res) => {
res.sendFile(__dirname + Routes.index)
})
//SECTION Play with graph schema
app.use(Routes.Graph, graphqlHTTP(req => ({
schema
,graphiql:true
})));
//SECTION The app
app.post(Routes.quotes, (req, res) => {
// Insert into TodoList Collection
var todoItem = new ToDo({
itemId: 1,
item: req.body.item,
completed: false
});
todoItem.save((err, result) => {
if (err) { console.log("---TodoItem save failed " + err) }
console.log("TodoItem saved successfully " + todoItem.item)
res.redirect(Routes.base)
});
})
export default app ;