mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
Change the server setup to use Express.js for hosting
This commit is contained in:
49
src/index.ts
49
src/index.ts
@@ -1,13 +1,11 @@
|
||||
import { readFileSync } from "fs";
|
||||
import { ApolloServer } from "@apollo/server";
|
||||
import { startStandaloneServer } from "@apollo/server/standalone";
|
||||
import { MergedResolvers } from "./MergedResolvers";
|
||||
import { ServerContext } from "./ServerContext";
|
||||
import { loadShuttleTestData } from "./loaders/shuttle/loadShuttleTestData";
|
||||
import { InterchangeSystem, InterchangeSystemBuilderArguments } from "./entities/InterchangeSystem";
|
||||
import { ChapmanApiBasedParkingRepositoryLoader } from "./loaders/parking/ChapmanApiBasedParkingRepositoryLoader";
|
||||
import { supportedIntegrationTestSystems } from "./loaders/supportedIntegrationTestSystems";
|
||||
import { loadParkingTestData } from "./loaders/parking/loadParkingTestData";
|
||||
import express from "express";
|
||||
import { expressMiddleware } from "@as-integrations/express5";
|
||||
|
||||
const typeDefs = readFileSync("./schema.graphqls", "utf8");
|
||||
|
||||
@@ -27,6 +25,7 @@ async function main() {
|
||||
resolvers: MergedResolvers,
|
||||
introspection: process.env.NODE_ENV !== "production",
|
||||
});
|
||||
await server.start();
|
||||
|
||||
let systems: InterchangeSystem[];
|
||||
|
||||
@@ -36,26 +35,30 @@ async function main() {
|
||||
},
|
||||
));
|
||||
|
||||
const { url } = await startStandaloneServer(server, {
|
||||
listen: {
|
||||
port: process.env.PORT ? parseInt(process.env.PORT) : 4000,
|
||||
},
|
||||
context: async () => {
|
||||
return {
|
||||
systems,
|
||||
findSystemById: (id: string) => {
|
||||
const system = systems.find((system) => system.id === id);
|
||||
if (!system) {
|
||||
return null;
|
||||
}
|
||||
return system;
|
||||
},
|
||||
}
|
||||
},
|
||||
const app = express();
|
||||
app.use(
|
||||
"/",
|
||||
express.json(),
|
||||
expressMiddleware(server, {
|
||||
context: async () => {
|
||||
return {
|
||||
systems,
|
||||
findSystemById: (id: string) => {
|
||||
const system = systems.find((system) => system.id === id);
|
||||
if (!system) {
|
||||
return null;
|
||||
}
|
||||
return system;
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
const port = process.env.PORT ? parseInt(process.env.PORT) : 4000;
|
||||
app.listen(port, () => {
|
||||
console.log(`Server ready at port ${port}`);
|
||||
});
|
||||
|
||||
|
||||
console.log(`Server ready at: ${url}`);
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
Reference in New Issue
Block a user