Change the server setup to use Express.js for hosting

This commit is contained in:
2025-08-26 11:02:03 -07:00
parent 8b8aae3ff9
commit 9856719e38
3 changed files with 56 additions and 28 deletions

View File

@@ -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();