Created
January 30, 2021 05:46
-
-
Save thawkin3/ce839aba676c2e0486d3626d4361b70f to your computer and use it in GitHub Desktop.
Apollo Server for the Dad Joke Dadabase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const path = require('path') | |
const { ApolloServer } = require('apollo-server-express') | |
const JokesAPI = require('./jokesAPI') | |
const RatingsAPI = require('./ratingsAPI') | |
const typeDefs = require('./typeDefs') | |
const resolvers = require('./resolvers') | |
const app = express() | |
const server = new ApolloServer({ | |
typeDefs, | |
resolvers, | |
dataSources: () => ({ | |
jokesAPI: new JokesAPI(), | |
ratingsAPI: new RatingsAPI(), | |
}), | |
}) | |
server.applyMiddleware({ app }) | |
app | |
.use(express.static(path.join(__dirname, 'public'))) | |
.get('/', (req, res) => { | |
res.sendFile('index.html', { root: 'public' }) | |
}) | |
.get('/script.js', (req, res) => { | |
res.sendFile('script.js', { root: 'public' }) | |
}) | |
.get('/style.css', (req, res) => { | |
res.sendFile('style.css', { root: 'public' }) | |
}) | |
app.listen({ port: process.env.PORT || 4000 }, () => { | |
console.log(`🚀 Server ready at port ${process.env.PORT || 4000}`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment