Skip to content

Instantly share code, notes, and snippets.

@thawkin3
Created January 30, 2021 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thawkin3/ce839aba676c2e0486d3626d4361b70f to your computer and use it in GitHub Desktop.
Save thawkin3/ce839aba676c2e0486d3626d4361b70f to your computer and use it in GitHub Desktop.
Apollo Server for the Dad Joke Dadabase
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