-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstarterFile.txt
43 lines (32 loc) · 1.04 KB
/
starterFile.txt
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
'use strict'
const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const graphqlHTTP = require('express-graphql')
const { makeExecutableSchema } = require('graphql-tools')
const firebaseClient = require('firebase')
const gqlServerConfig = require('./api')
if (process.env.NODE_ENV === 'development') {
require('dotenv').config({ path: 'development.env' })
}
const app = express()
app.set('port', process.env.PORT || 7000)
app.use(bodyParser.json({ limit: '10mb' }))
app.use(bodyParser.urlencoded({ extended: true }))
app.use(cors())
const schema = makeExecutableSchema(gqlServerConfig)
const firebase = firebaseClient.initializeApp({
apiKey: process.env.FIREBASE_API_KEY,
databaseURL: process.env.FIREBASE_DATABASE_URL
});
app.use('/graphql', (req, res) => {
graphqlHTTP({
schema,
graphiql: true,
context: { firebase }
})(req, res)
})
const server = app.listen(app.get('port'), () => {
console.log(`Server running -> PORT ${server.address().port}`)
})
module.exports = app