-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (26 loc) · 779 Bytes
/
server.js
File metadata and controls
35 lines (26 loc) · 779 Bytes
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
import express from 'express'
import bodyParser from 'body-parser'
import mongoose from 'mongoose'
import graphqlHTTP from 'express-graphql'
import schema from './source/graphql'
import config from './source/config'
const app = express()
const PORT = 8000
mongoose.Promise = global.Promise
mongoose.connect(config.mongodb.uri, {
useMongoClient: true
})
mongoose.connection
.on('error', () => console.log('failed to connect to database'))
.on('open', () => console.log('Connected to DB.'))
// GraphQL API endpoint
app.use('/graphql', graphqlHTTP(() => ({
schema,
graphiql: true,
pretty: true
})))
app.use(bodyParser.json())
app.get('/', (req, res) => {
res.send('Server is running!')
})
app.listen(PORT, () => console.log(`App listening on port ${PORT}!`))