-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (32 loc) · 982 Bytes
/
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
35
36
37
38
39
import { } from 'dotenv/config';
import express from 'express';
import bodyParser from 'body-parser';
import {
graphqlExpress,
graphiqlExpress
} from 'graphql-server-express';
import cors from 'cors';
import admin from './database/firebase';
import firebaseAuthMiddleware from './api/middleware';
import schema from './api/schema';
import createLoaders from './api/loaders';
const GQL_PORT = 4400;
const app = express();
const PORT = process.env.PORT;
app.use('*', cors());
app.use(bodyParser.json());
app.use('/graphql', firebaseAuthMiddleware);
app.use('/graphql', graphqlExpress(function(req, res) {
return {
schema,
context: {
loaders: createLoaders()
}
}
})); // set up graphql endpoint
app.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql' // need to tell graphiql where the graphql endpoint is
}));
app.listen(GQL_PORT, () => console.log(
`GraphQL is now running localhost:${GQL_PORT}/graphql`
));