index.js 1.4 KB

123456789101112131415161718192021222324252627
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.startStandaloneServer = void 0;
  7. const cors_1 = __importDefault(require("cors"));
  8. const express_1 = __importDefault(require("express"));
  9. const http_1 = __importDefault(require("http"));
  10. const index_js_1 = require("../express4/index.js");
  11. const index_js_2 = require("../plugin/drainHttpServer/index.js");
  12. const urlForHttpServer_js_1 = require("../utils/urlForHttpServer.js");
  13. async function startStandaloneServer(server, options) {
  14. const app = (0, express_1.default)();
  15. const httpServer = http_1.default.createServer(app);
  16. server.addPlugin((0, index_js_2.ApolloServerPluginDrainHttpServer)({ httpServer: httpServer }));
  17. await server.start();
  18. const context = options?.context ?? (async () => ({}));
  19. app.use((0, cors_1.default)(), express_1.default.json({ limit: '50mb' }), (0, index_js_1.expressMiddleware)(server, { context }));
  20. const listenOptions = options?.listen ?? { port: 4000 };
  21. await new Promise((resolve) => {
  22. httpServer.listen(listenOptions, resolve);
  23. });
  24. return { url: (0, urlForHttpServer_js_1.urlForHttpServer)(httpServer) };
  25. }
  26. exports.startStandaloneServer = startStandaloneServer;
  27. //# sourceMappingURL=index.js.map