index.js 936 B

1234567891011121314151617181920
  1. import cors from 'cors';
  2. import express from 'express';
  3. import http from 'http';
  4. import { expressMiddleware } from '../express4/index.js';
  5. import { ApolloServerPluginDrainHttpServer } from '../plugin/drainHttpServer/index.js';
  6. import { urlForHttpServer } from '../utils/urlForHttpServer.js';
  7. export async function startStandaloneServer(server, options) {
  8. const app = express();
  9. const httpServer = http.createServer(app);
  10. server.addPlugin(ApolloServerPluginDrainHttpServer({ httpServer: httpServer }));
  11. await server.start();
  12. const context = options?.context ?? (async () => ({}));
  13. app.use(cors(), express.json({ limit: '50mb' }), expressMiddleware(server, { context }));
  14. const listenOptions = options?.listen ?? { port: 4000 };
  15. await new Promise((resolve) => {
  16. httpServer.listen(listenOptions, resolve);
  17. });
  18. return { url: urlForHttpServer(httpServer) };
  19. }
  20. //# sourceMappingURL=index.js.map