-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
62 additions
and
51 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,17 @@ | ||
import express from "express"; | ||
import { expressMiddleware } from "@apollo/server/express4"; | ||
import loaders from "./loaders"; | ||
import { Config } from "../config"; | ||
import http from "http"; | ||
|
||
export default async (config: Config) => { | ||
const app = express(); | ||
|
||
const server = await loaders(app); | ||
await server.start(); | ||
|
||
app.use( | ||
"/graphql", | ||
expressMiddleware(server, { | ||
context: async ({ req }) => ({ | ||
user: { | ||
...req.user, | ||
isAuthenticated: req.isAuthenticated(), | ||
logout: (callback: (err: any) => void) => req.logout(callback), | ||
}, | ||
}), | ||
}) | ||
); | ||
await loaders(app); | ||
|
||
const httpServer = http.createServer(app); | ||
|
||
await new Promise<void>((resolve) => | ||
httpServer.listen({ port: config.port }, resolve) | ||
); | ||
console.log( | ||
`🚀 Server ready at http://localhost:${config.port}${config.graphqlPath}` | ||
); | ||
await httpServer.listen(config.port) | ||
|
||
console.log(`🚀\tServer ready (in Docker network) at:\thttp://localhost:${config.port}${config.backendPath}`); | ||
console.log(`\tServer ready (in Host network) at:\thttp://localhost:8080${config.backendPath}`) | ||
}; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
import type { Application } from "express"; | ||
import type { ApolloServer } from "@apollo/server"; | ||
import { type Application, Router } from "express"; | ||
import { config } from "../../config"; | ||
|
||
// loaders | ||
import apolloLoader from "./apollo"; | ||
import expressLoader from "./express"; | ||
import mongooseLoader from "./mongoose"; | ||
import passportLoader from './passport'; | ||
|
||
export default async (app: Application): Promise<ApolloServer> => { | ||
// Load everything related to express | ||
console.log("Booting up express..."); | ||
await expressLoader(app); | ||
export default async (root: Application): Promise<void> => { | ||
const app = Router() as Application; | ||
|
||
console.log("Booting up passport..."); | ||
await passportLoader(app); | ||
|
||
// Connect to mongoose | ||
// connect to mongoose | ||
console.log("Booting up mongo..."); | ||
await mongooseLoader(); | ||
|
||
// load apollo server config | ||
console.log("Booting up apollo..."); | ||
return apolloLoader(); | ||
// load apollo server config. must be loaded before express | ||
console.log("Loading apollo..."); | ||
const server = await apolloLoader(); | ||
|
||
// load everything related to express. depends on apollo | ||
console.log("Loading express..."); | ||
await expressLoader(app, server); | ||
|
||
// append backend path to all routes | ||
root.use(config.backendPath, app); | ||
}; |
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
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
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
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