Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

Commit

Permalink
fix for random crashing and proper express auth
Browse files Browse the repository at this point in the history
  • Loading branch information
sebasptsch committed Mar 4, 2022
1 parent 4e7a935 commit d6d0f91
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 253 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"@discordjs/builders": "^0.9.0",
"@discordjs/rest": "^0.1.0-canary.0",
"@prisma/client": "^3.10.0",
"apollo-server": "^3.6.3",
"apollo-server-core": "^3.6.3",
"apollo-server-express": "^3.6.3",
"discord-api-types": "^0.25.2",
"discord.js": "^13.3.1",
"dotenv": "^10.0.0",
"express": "^4.17.2",
"express-graphql": "^0.12.0",
"express": "^4.17.3",
"fuse.js": "^6.5.3",
"graphql": "^16.3.0",
"lodash": "^4.17.21",
Expand Down Expand Up @@ -61,4 +61,4 @@
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
}
}
}
26 changes: 21 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { ApolloServer, gql } from "apollo-server";
import { ApolloServer } from 'apollo-server-express';
import { ApolloServerPluginDrainHttpServer, gql } from 'apollo-server-core';
import express from 'express';
import http from 'http';
import { Client, Intents } from "discord.js";
import dotenv from "dotenv";
import * as events from "./events/index";
Expand All @@ -18,7 +21,6 @@ var typeDefs = gql`
type Mutation {
prune: PruneResponse!
// TODO: Add the ability to refresh commands like in the scripts
}
type DiscordVoiceChannel {
Expand Down Expand Up @@ -206,9 +208,23 @@ const resolvers = {
discordChannel: async (parent) => await client.channels.fetch(parent.id),
},
};

const server = new ApolloServer({ resolvers, typeDefs });
server.listen({ port: 4000 });
(async () => {
const app = express()
const httpServer = http.createServer(app)
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [ApolloServerPluginDrainHttpServer({httpServer})]
})
await server.start()
server.applyMiddleware({
app,
path: '/graphql'
})
await new Promise<void>(resolve => httpServer.listen({ port: 4000 }, resolve));
console.log(`🚀 Server ready at http://localhost:4000${server.graphqlPath}`);

})

/**
* DiscordJS Client instance
Expand Down
Loading

0 comments on commit d6d0f91

Please sign in to comment.