@things-factory/shell 8.0.0-alpha.8 → 8.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env bash
2
+
3
+ echo $1
4
+ echo $2
5
+
6
+ PLATFORM=linux/amd64
7
+
8
+ if [ $# -eq 0 ] ; then
9
+ echo "Image name required"
10
+ exit 1;
11
+ else
12
+ IMAGE=$1
13
+ PLATFORM=$2
14
+ fi
15
+
16
+ echo "IMAGE : ${IMAGE}"
17
+ echo "PLATFORM : ${PLATFORM}"
18
+
19
+ # Dockerfile4ARM을 사용하여 Docker 이미지를 빌드
20
+ DOCKER_BUILDKIT=1 docker image build -f Dockerfile-arm64 -t ${IMAGE} --platform ${PLATFORM} .
package/client/store.js CHANGED
@@ -5,7 +5,8 @@ import route from './reducers/route.js'
5
5
 
6
6
  export const store = configureStore({
7
7
  // set false due to causing severe conflicts with redux-devtools.
8
- devTools: false // process.env['NODE-ENV'] !== 'production'
8
+ // devTools: false // process.env['NODE-ENV'] !== 'production'
9
+ devTools: process.env['NODE-ENV'] !== 'production'
9
10
  })
10
11
 
11
12
  store.addReducers({
@@ -9,7 +9,8 @@ body {
9
9
  /* monthly layout */
10
10
  --calendar-monthly-ol-margin: var(--margin-default) 0;
11
11
  --calendar-monthly-ol-top-border: 2px solid var(--md-sys-color-secondary);
12
- --calendar-current-monty-background-color: var(--md-sys-color-surface-variant);
12
+ --calendar-current-month-background-color: var(--md-sys-color-surface-variant);
13
+ --calendar-current-month-color: var(--md-sys-color-on-surface);
13
14
  --calendar-monthly-label-align: left;
14
15
  --calendar-monthly-label-padding: var(--padding-narrow) 0;
15
16
  --calendar-monthly-label-color: var(--md-sys-color-secondary);
@@ -35,6 +36,7 @@ body {
35
36
  --calendar-weekly-ol-margin: var(--margin-default) 0;
36
37
  --calendar-weekly-ol-top-border: 2px solid var(--md-sys-color-secondary);
37
38
  --calendar-current-week-background-color: var(--md-sys-color-surface-variant);
39
+ --calendar-current-week-color: var(--md-sys-color-on-surface);
38
40
  --calendar-weekly-label-align: center;
39
41
  --calendar-weekly-label-padding: var(--padding-narrow) 0;
40
42
  --calendar-weekly-label-color: var(--md-sys-color-secondary);
@@ -1,9 +1,10 @@
1
+ html,
1
2
  body {
2
3
  margin: 0;
3
4
  padding: 0;
4
5
  overflow: hidden;
5
6
 
6
- overscroll-behavior-y: none;
7
+ overscroll-behavior: none;
7
8
 
8
9
  /* This is a font-stack that tries to use the system-default sans-serifs first */
9
10
  font-family: Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
@@ -2,6 +2,7 @@ module.exports = {
2
2
  domainType: '',
3
3
  port: 3000,
4
4
  subdomainOffset: 2,
5
+ keepAliveTimeout: 65000,
5
6
  CSP: {
6
7
  /* Content Security Policy
7
8
  * ie.
@@ -23,7 +23,6 @@ const koa2_connect_history_api_fallback_1 = require("koa2-connect-history-api-fa
23
23
  const ws_2 = require("ws");
24
24
  const co_1 = tslib_1.__importDefault(require("co"));
25
25
  const http_2 = tslib_1.__importDefault(require("http"));
26
- const koa_webpack_1 = tslib_1.__importDefault(require("@hatiolab/koa-webpack"));
27
26
  const cors_1 = tslib_1.__importDefault(require("@koa/cors"));
28
27
  const crypto_1 = tslib_1.__importDefault(require("crypto"));
29
28
  const env_1 = require("@things-factory/env");
@@ -33,6 +32,7 @@ const database_1 = require("./initializers/database");
33
32
  const routers_1 = require("./routers");
34
33
  const schema_1 = require("./schema");
35
34
  const middlewares_1 = require("./middlewares");
35
+ const wdm = require('webpack-dev-middleware');
36
36
  process.on('uncaughtException', error => {
37
37
  env_1.logger.error('uncaughtException: ', error);
38
38
  //process.exit(1)
@@ -171,14 +171,6 @@ const bootstrap = async () => {
171
171
  cache: false,
172
172
  debug: false
173
173
  });
174
- const middleware = await (0, koa_webpack_1.default)({
175
- compiler,
176
- hotClient: {},
177
- devMiddleware: {
178
- publicPath: webpackConfig.output.publicPath,
179
- stats: { colors: true }
180
- }
181
- });
182
174
  // only for development mode. triggered after webpack compilation is done.
183
175
  compiler.hooks.done.tap({ name: 'server-dev' }, stats => {
184
176
  process.emit('client-rebuilt', app, compiler.outputFileSystem);
@@ -211,7 +203,9 @@ const bootstrap = async () => {
211
203
  app.use(routers_1.graphqlRouter.allowedMethods());
212
204
  /* should follow this order : history-fallback => webpack-middleware */
213
205
  app.use((0, koa2_connect_history_api_fallback_1.historyApiFallback)({ whiteList: [] }));
214
- app.use(middleware);
206
+ app.use(wdm.koaWrapper(compiler, {
207
+ publicPath: webpackConfig.output.publicPath
208
+ }));
215
209
  httpServer.listen({ port: PORT }, () => {
216
210
  env_1.logger.info(`🚀 Server ready at http://0.0.0.0:${PORT}/graphql`);
217
211
  env_1.logger.info(`🚀 Subscriptions ready at ws://0.0.0.0:${PORT}/graphql`);
@@ -1 +1 @@
1
- {"version":3,"file":"server-dev.js","sourceRoot":"","sources":["../server/server-dev.ts"],"names":[],"mappings":";AAAA,4BAA4B;;;AAE5B,4DAA4D;AAC5D,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AACxB,OAAO,CAAC,GAAG,CAAC,kBAAkB,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,CAAA;AAEjD,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;AAEjE,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,aAAa,CAAA;AACpC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;AAE1B,2CAA6C;AAC7C,2EAAyF;AACzF,uEAAqG;AAErG,8CAAoD;AACpD,0DAA+B;AAC/B,qGAAiE;AACjE,8CAAiD;AACjD,+BAAmC;AACnC,sDAAqB;AACrB,4EAA0C;AAC1C,sEAAiC;AACjC,yFAAsE;AACtE,2BAAoC;AACpC,oDAAmB;AACnB,wDAAuB;AAEvB,gFAA8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,SAAS,EAAE,CAAA","sourcesContent":["// ts-import-sorter: disable\n\n/* following 7 lines should be located in top of the file */\nconst OS = require('os')\nprocess.env.UV_THREADPOOL_SIZE = OS.cpus().length\n\nconsole.log('UV_THREADPOOL_SIZE', process.env.UV_THREADPOOL_SIZE)\n\nprocess.env.NODE_ENV = 'development'\nprocess.setMaxListeners(0)\n\nimport { ApolloServer } from '@apollo/server'\nimport { ApolloServerPluginDrainHttpServer } from '@apollo/server/plugin/drainHttpServer'\nimport { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin/landingPage/default'\n\nimport { koaMiddleware } from '@as-integrations/koa'\nimport bytesFormat from 'bytes'\nimport graphqlUploadKoa from 'graphql-upload/graphqlUploadKoa.js'\nimport { useServer } from 'graphql-ws/lib/use/ws'\nimport { createServer } from 'http'\nimport Koa from 'koa'\nimport koaBodyParser from 'koa-bodyparser'\nimport compose from 'koa-compose'\nimport { historyApiFallback } from 'koa2-connect-history-api-fallback'\nimport { WebSocketServer } from 'ws'\nimport co from 'co'\nimport http from 'http'\n\nimport koaWebpack from '@hatiolab/koa-webpack'\nimport cors from '@koa/cors'\n\nimport crypto from 'crypto'\n\nimport { config, loader, logger, orderedModuleNames } from '@things-factory/env'\nimport { initLicense, checkValidity } from '@things-factory/operato-license-checker'\n\nimport { GraphqlLocalClient } from './graphql-local-client'\nimport { databaseInitializer } from './initializers/database'\nimport {\n domainPrivateRouter,\n domainPublicRouter,\n globalPrivateRouter,\n globalPublicRouter,\n graphqlRouter\n} from './routers'\nimport { schema } from './schema'\nimport { Domain } from './service'\nimport { EntityManager } from 'typeorm'\nimport { domainMiddleware } from './middlewares'\n\nprocess.on('uncaughtException', error => {\n logger.error('uncaughtException: ', error)\n\n //process.exit(1)\n})\n\nconst args = require('args')\n\nargs.option('port', 'The port on which the app will be running', config.get('port', 3000))\nargs.option(\n 'inspect',\n `The address on which the inspection will be running. Used in development mode only.\n This option is just to prevent termination for reasons of not recognizing the 'inspect' option.`,\n config.get('inspect', ':9229')\n)\nargs.option('webpack', 'webpack configuration file', config.get('webpack'))\n\nconst flags = args.parse(process.argv)\n\nconst webpack = require('webpack')\nconst webpackConfig = require(flags.webpack || '@things-factory/builder/webpack.config.dev.js')\n\nconst compiler = webpack(webpackConfig)\n\nconst PORT = (process.env.PORT = flags.port)\n\nconst requestBody = config.get('requestBody') || {}\n\nconst bodyParserOption = {\n formLimit: requestBody.formLimit || '10mb',\n jsonLimit: requestBody.jsonLimit || '10mb',\n textLimit: requestBody.textLimit || '10mb'\n}\n\nconst fileUpload = config.get('fileUpload') || {}\nconst fileUploadOption = {\n maxFileSize: bytesFormat.parse(fileUpload.maxFileSize) || bytesFormat.parse('10mb'),\n maxFiles: fileUpload.maxFiles || 10\n}\n\ninterface ICustomAppState {\n domain: Domain\n user: any\n tx: EntityManager\n}\n\ninterface ICustomAppContext {\n t: any\n ssoMiddlewares: any[]\n}\n\ninitLicense(config.get('licenseKey'))\n\n/* bootstrap */\nconst bootstrap = async () => {\n await databaseInitializer()\n\n const app = new Koa<ICustomAppState, ICustomAppContext>() as any\n app.proxy = true\n\n app.use(\n cors({\n origin: function (ctx) {\n return ctx.request.headers.origin || '*'\n },\n exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],\n maxAge: 5,\n credentials: true,\n /* allowMethods: ['GET', 'POST', 'DELETE'], -- use default */\n allowHeaders: ['Content-Type', 'Authorization', 'Accept']\n })\n )\n\n app.use(async (ctx, next) => {\n ctx.set('X-Content-Type-Options', 'nosniff')\n\n const { directives = {} } = config.get('CSP') || {}\n\n const nonce = crypto.randomBytes(16).toString('base64')\n ctx.state.nonce = nonce\n\n const cspHeader = Object.entries(directives as { [key: string]: string[] })\n .map(([key, value]) => `${key} ${value.join(' ')}`)\n .join('; ')\n\n ctx.set('Content-Security-Policy', cspHeader)\n\n await next()\n })\n\n var subscriptionMiddleware = []\n process.emit('bootstrap-module-subscription' as any, app, subscriptionMiddleware)\n\n const builtSchema = await schema()\n\n const httpServer = createServer(app.callback())\n const websocketServer = new WebSocketServer({\n server: httpServer,\n path: '/graphql'\n })\n\n // Save the returned server's info so we can shut down this server later\n const serverCleanup = useServer(\n {\n schema: builtSchema,\n context: async (ctx, msg, args) => {\n return ctx['context']\n },\n onConnect: async ctx => {\n var { extra, connectionParams } = ctx\n var { request } = extra\n\n if (((connectionParams['headers'] as any) || connectionParams)?.referer) {\n var url = new URL(((connectionParams['headers'] as any) || connectionParams).referer)\n var accessToken = url.searchParams.get('access_token')\n if (accessToken) {\n connectionParams['headers']['authorization'] = accessToken\n }\n }\n\n request.headers = {\n ...request.headers,\n ...(connectionParams['headers'] || (connectionParams as any))\n }\n\n var koacontext = await app.createContext(request, new http.ServerResponse(request))\n koacontext['state'] = {}\n\n /* in case connect error(like a authentication error) just throw exception */\n var middlewares = [domainMiddleware, ...subscriptionMiddleware]\n const fn = co.wrap(compose(middlewares))\n\n await fn(koacontext)\n\n return (ctx['context'] = koacontext)\n },\n onDisconnect(ctx, code, reason) {\n console.log('Disconnected!')\n },\n onError(ctx, msg, errors) {\n console.error(msg, errors)\n }\n },\n websocketServer\n )\n\n const server = new ApolloServer({\n schema: builtSchema,\n formatError: error => {\n logger.error(error)\n return error\n },\n introspection: true,\n csrfPrevention: true,\n plugins: [\n // Proper shutdown for the HTTP server.\n ApolloServerPluginDrainHttpServer({ httpServer }),\n // Proper shutdown for the WebSocket server.\n {\n async serverWillStart() {\n return {\n async drainServer() {\n await serverCleanup.dispose()\n }\n }\n }\n },\n // TODO make this landing page work\n ApolloServerPluginLandingPageLocalDefault({\n footer: false,\n embed: true,\n includeCookies: true\n })\n ],\n cache: 'bounded'\n })\n\n await server.start()\n\n GraphqlLocalClient.init(builtSchema, app)\n\n orderedModuleNames.forEach(name => {\n const { initMiddlewares } = loader(name)\n initMiddlewares && initMiddlewares(app)\n })\n\n const render = require('@things-factory/ejs-remote')\n render(app, {\n root: '/views',\n host: `http://127.0.0.1:${PORT}`,\n layout: false,\n viewExt: 'html',\n cache: false,\n debug: false\n })\n\n const middleware = await koaWebpack({\n compiler,\n hotClient: {},\n devMiddleware: {\n publicPath: webpackConfig.output.publicPath,\n stats: { colors: true }\n }\n })\n\n // only for development mode. triggered after webpack compilation is done.\n compiler.hooks.done.tap({ name: 'server-dev' }, stats => {\n process.emit('client-rebuilt' as any, app, compiler.outputFileSystem)\n })\n\n app.use(koaBodyParser(bodyParserOption))\n\n /* routers */\n const ssoMiddlewares = []\n process.emit('bootstrap-collect-sso-middleware' as any, null, ssoMiddlewares)\n app.ssoMiddlewares = ssoMiddlewares\n\n process.emit('bootstrap-module-global-public-route' as any, app, globalPublicRouter)\n process.emit('bootstrap-module-global-private-route' as any, app, globalPrivateRouter)\n process.emit('bootstrap-module-domain-public-route' as any, app, domainPublicRouter)\n process.emit('bootstrap-module-domain-private-route' as any, app, domainPrivateRouter)\n\n app.use(checkValidity) /* Check the license after most of the context has been built */\n\n app\n .use(globalPublicRouter.routes())\n .use(globalPublicRouter.allowedMethods())\n .use(globalPrivateRouter.routes())\n .use(globalPrivateRouter.allowedMethods())\n .use(domainPublicRouter.routes())\n .use(domainPublicRouter.allowedMethods())\n .use(domainPrivateRouter.routes())\n .use(domainPrivateRouter.allowedMethods())\n\n /* Graphql Upload's multipart/form-data handling affects the restful file upload feature, so it should be placed after the routers configuration. */\n app.use(graphqlUploadKoa(fileUploadOption))\n\n graphqlRouter.post(\n '/graphql',\n koaMiddleware(server, {\n context: async ({ ctx }) => ctx\n })\n )\n app.use(graphqlRouter.routes())\n app.use(graphqlRouter.allowedMethods())\n\n /* should follow this order : history-fallback => webpack-middleware */\n app.use(historyApiFallback({ whiteList: [] }))\n\n app.use(middleware)\n\n httpServer.listen({ port: PORT }, () => {\n logger.info(`🚀 Server ready at http://0.0.0.0:${PORT}/graphql`)\n logger.info(`🚀 Subscriptions ready at ws://0.0.0.0:${PORT}/graphql`)\n\n process.emit('bootstrap-module-start' as any, { app, config, builtSchema, httpServer } as any)\n })\n}\n\nbootstrap()\n"]}
1
+ {"version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DAAkB,EAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;IAE9C,GAAG,CAAC,GAAG,CACL,GAAG,CAAC,UAAU,CAAC,QAAQ,EAAE;QACvB,UAAU,EAAE,aAAa,CAAC,MAAM,CAAC,UAAU;KAC5C,CAAC,CACH,CAAA;IAED,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE;QACrC,YAAM,CAAC,IAAI,CAAC,qCAAqC,IAAI,UAAU,CAAC,CAAA;QAChE,YAAM,CAAC,IAAI,CAAC,0CAA0C,IAAI,UAAU,CAAC,CAAA;QAErE,OAAO,CAAC,IAAI,CAAC,wBAA+B,EAAE,EAAE,GAAG,EAAE,MAAM,EAAN,YAAM,EAAE,WAAW,EAAE,UAAU,EAAS,CAAC,CAAA;IAChG,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,SAAS,EAAE,CAAA","sourcesContent":["// ts-import-sorter: disable\n\n/* following 7 lines should be located in top of the file */\nconst OS = require('os')\nprocess.env.UV_THREADPOOL_SIZE = OS.cpus().length\n\nconsole.log('UV_THREADPOOL_SIZE', process.env.UV_THREADPOOL_SIZE)\n\nprocess.env.NODE_ENV = 'development'\nprocess.setMaxListeners(0)\n\nimport { ApolloServer } from '@apollo/server'\nimport { ApolloServerPluginDrainHttpServer } from '@apollo/server/plugin/drainHttpServer'\nimport { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin/landingPage/default'\n\nimport { koaMiddleware } from '@as-integrations/koa'\nimport bytesFormat from 'bytes'\nimport graphqlUploadKoa from 'graphql-upload/graphqlUploadKoa.js'\nimport { useServer } from 'graphql-ws/lib/use/ws'\nimport { createServer } from 'http'\nimport Koa from 'koa'\nimport koaBodyParser from 'koa-bodyparser'\nimport compose from 'koa-compose'\nimport { historyApiFallback } from 'koa2-connect-history-api-fallback'\nimport { WebSocketServer } from 'ws'\nimport co from 'co'\nimport http from 'http'\n\nimport cors from '@koa/cors'\n\nimport crypto from 'crypto'\n\nimport { config, loader, logger, orderedModuleNames } from '@things-factory/env'\nimport { initLicense, checkValidity } from '@things-factory/operato-license-checker'\n\nimport { GraphqlLocalClient } from './graphql-local-client'\nimport { databaseInitializer } from './initializers/database'\nimport {\n domainPrivateRouter,\n domainPublicRouter,\n globalPrivateRouter,\n globalPublicRouter,\n graphqlRouter\n} from './routers'\nimport { schema } from './schema'\nimport { Domain } from './service'\nimport { EntityManager } from 'typeorm'\nimport { domainMiddleware } from './middlewares'\nconst wdm = require('webpack-dev-middleware')\n\nprocess.on('uncaughtException', error => {\n logger.error('uncaughtException: ', error)\n\n //process.exit(1)\n})\n\nconst args = require('args')\n\nargs.option('port', 'The port on which the app will be running', config.get('port', 3000))\nargs.option(\n 'inspect',\n `The address on which the inspection will be running. Used in development mode only.\n This option is just to prevent termination for reasons of not recognizing the 'inspect' option.`,\n config.get('inspect', ':9229')\n)\nargs.option('webpack', 'webpack configuration file', config.get('webpack'))\n\nconst flags = args.parse(process.argv)\n\nconst webpack = require('webpack')\nconst webpackConfig = require(flags.webpack || '@things-factory/builder/webpack.config.dev.js')\n\nconst compiler = webpack(webpackConfig)\n\nconst PORT = (process.env.PORT = flags.port)\n\nconst requestBody = config.get('requestBody') || {}\n\nconst bodyParserOption = {\n formLimit: requestBody.formLimit || '10mb',\n jsonLimit: requestBody.jsonLimit || '10mb',\n textLimit: requestBody.textLimit || '10mb'\n}\n\nconst fileUpload = config.get('fileUpload') || {}\nconst fileUploadOption = {\n maxFileSize: bytesFormat.parse(fileUpload.maxFileSize) || bytesFormat.parse('10mb'),\n maxFiles: fileUpload.maxFiles || 10\n}\n\ninterface ICustomAppState {\n domain: Domain\n user: any\n tx: EntityManager\n}\n\ninterface ICustomAppContext {\n t: any\n ssoMiddlewares: any[]\n}\n\ninitLicense(config.get('licenseKey'))\n\n/* bootstrap */\nconst bootstrap = async () => {\n await databaseInitializer()\n\n const app = new Koa<ICustomAppState, ICustomAppContext>() as any\n app.proxy = true\n\n app.use(\n cors({\n origin: function (ctx) {\n return ctx.request.headers.origin || '*'\n },\n exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],\n maxAge: 5,\n credentials: true,\n /* allowMethods: ['GET', 'POST', 'DELETE'], -- use default */\n allowHeaders: ['Content-Type', 'Authorization', 'Accept']\n })\n )\n\n app.use(async (ctx, next) => {\n ctx.set('X-Content-Type-Options', 'nosniff')\n\n const { directives = {} } = config.get('CSP') || {}\n\n const nonce = crypto.randomBytes(16).toString('base64')\n ctx.state.nonce = nonce\n\n const cspHeader = Object.entries(directives as { [key: string]: string[] })\n .map(([key, value]) => `${key} ${value.join(' ')}`)\n .join('; ')\n\n ctx.set('Content-Security-Policy', cspHeader)\n\n await next()\n })\n\n var subscriptionMiddleware = []\n process.emit('bootstrap-module-subscription' as any, app, subscriptionMiddleware)\n\n const builtSchema = await schema()\n\n const httpServer = createServer(app.callback())\n const websocketServer = new WebSocketServer({\n server: httpServer,\n path: '/graphql'\n })\n\n // Save the returned server's info so we can shut down this server later\n const serverCleanup = useServer(\n {\n schema: builtSchema,\n context: async (ctx, msg, args) => {\n return ctx['context']\n },\n onConnect: async ctx => {\n var { extra, connectionParams } = ctx\n var { request } = extra\n\n if (((connectionParams['headers'] as any) || connectionParams)?.referer) {\n var url = new URL(((connectionParams['headers'] as any) || connectionParams).referer)\n var accessToken = url.searchParams.get('access_token')\n if (accessToken) {\n connectionParams['headers']['authorization'] = accessToken\n }\n }\n\n request.headers = {\n ...request.headers,\n ...(connectionParams['headers'] || (connectionParams as any))\n }\n\n var koacontext = await app.createContext(request, new http.ServerResponse(request))\n koacontext['state'] = {}\n\n /* in case connect error(like a authentication error) just throw exception */\n var middlewares = [domainMiddleware, ...subscriptionMiddleware]\n const fn = co.wrap(compose(middlewares))\n\n await fn(koacontext)\n\n return (ctx['context'] = koacontext)\n },\n onDisconnect(ctx, code, reason) {\n console.log('Disconnected!')\n },\n onError(ctx, msg, errors) {\n console.error(msg, errors)\n }\n },\n websocketServer\n )\n\n const server = new ApolloServer({\n schema: builtSchema,\n formatError: error => {\n logger.error(error)\n return error\n },\n introspection: true,\n csrfPrevention: true,\n plugins: [\n // Proper shutdown for the HTTP server.\n ApolloServerPluginDrainHttpServer({ httpServer }),\n // Proper shutdown for the WebSocket server.\n {\n async serverWillStart() {\n return {\n async drainServer() {\n await serverCleanup.dispose()\n }\n }\n }\n },\n // TODO make this landing page work\n ApolloServerPluginLandingPageLocalDefault({\n footer: false,\n embed: true,\n includeCookies: true\n })\n ],\n cache: 'bounded'\n })\n\n await server.start()\n\n GraphqlLocalClient.init(builtSchema, app)\n\n orderedModuleNames.forEach(name => {\n const { initMiddlewares } = loader(name)\n initMiddlewares && initMiddlewares(app)\n })\n\n const render = require('@things-factory/ejs-remote')\n render(app, {\n root: '/views',\n host: `http://127.0.0.1:${PORT}`,\n layout: false,\n viewExt: 'html',\n cache: false,\n debug: false\n })\n\n // only for development mode. triggered after webpack compilation is done.\n compiler.hooks.done.tap({ name: 'server-dev' }, stats => {\n process.emit('client-rebuilt' as any, app, compiler.outputFileSystem)\n })\n\n app.use(koaBodyParser(bodyParserOption))\n\n /* routers */\n const ssoMiddlewares = []\n process.emit('bootstrap-collect-sso-middleware' as any, null, ssoMiddlewares)\n app.ssoMiddlewares = ssoMiddlewares\n\n process.emit('bootstrap-module-global-public-route' as any, app, globalPublicRouter)\n process.emit('bootstrap-module-global-private-route' as any, app, globalPrivateRouter)\n process.emit('bootstrap-module-domain-public-route' as any, app, domainPublicRouter)\n process.emit('bootstrap-module-domain-private-route' as any, app, domainPrivateRouter)\n\n app.use(checkValidity) /* Check the license after most of the context has been built */\n\n app\n .use(globalPublicRouter.routes())\n .use(globalPublicRouter.allowedMethods())\n .use(globalPrivateRouter.routes())\n .use(globalPrivateRouter.allowedMethods())\n .use(domainPublicRouter.routes())\n .use(domainPublicRouter.allowedMethods())\n .use(domainPrivateRouter.routes())\n .use(domainPrivateRouter.allowedMethods())\n\n /* Graphql Upload's multipart/form-data handling affects the restful file upload feature, so it should be placed after the routers configuration. */\n app.use(graphqlUploadKoa(fileUploadOption))\n\n graphqlRouter.post(\n '/graphql',\n koaMiddleware(server, {\n context: async ({ ctx }) => ctx\n })\n )\n app.use(graphqlRouter.routes())\n app.use(graphqlRouter.allowedMethods())\n\n /* should follow this order : history-fallback => webpack-middleware */\n app.use(historyApiFallback({ whiteList: [] }))\n\n app.use(\n wdm.koaWrapper(compiler, {\n publicPath: webpackConfig.output.publicPath\n })\n )\n\n httpServer.listen({ port: PORT }, () => {\n logger.info(`🚀 Server ready at http://0.0.0.0:${PORT}/graphql`)\n logger.info(`🚀 Subscriptions ready at ws://0.0.0.0:${PORT}/graphql`)\n\n process.emit('bootstrap-module-start' as any, { app, config, builtSchema, httpServer } as any)\n })\n}\n\nbootstrap()\n"]}
@@ -196,6 +196,24 @@ const bootstrap = async () => {
196
196
  app.use((0, koa_static_1.default)(path.join(process.cwd(), 'dist-app'), {
197
197
  index: 'index.html'
198
198
  }));
199
+ // Set keep-alive timeout from configuration or fallback to default (65000ms).
200
+ // The keepAliveTimeout determines how long the server will keep an idle connection
201
+ // alive before closing it.
202
+ const keepAliveTimeout = env_1.config.get('keepAliveTimeout', 65000);
203
+ // Apply the configured keep-alive timeout to the server. If no configuration is
204
+ // provided, default to 65000ms (65 seconds). In the context of an external load balancer,
205
+ // this timeout is critical for maintaining persistent connections between the load
206
+ // balancer and the server. Setting a sufficiently long keepAliveTimeout minimizes
207
+ // the need to constantly re-establish TCP connections, improving efficiency and
208
+ // reducing connection overhead.
209
+ httpServer.keepAliveTimeout = keepAliveTimeout || 65000;
210
+ // Set headersTimeout to be 1000ms (1 second) longer than keepAliveTimeout.
211
+ // This ensures the server has sufficient time to receive headers from the client
212
+ // before closing the connection, preventing premature disconnections. In the context
213
+ // of a load balancer, this ensures that if the load balancer is sending headers
214
+ // slowly (due to network delays or other factors), the connection isn't closed
215
+ // before the headers are fully transmitted.
216
+ httpServer.headersTimeout = keepAliveTimeout + 1000;
199
217
  httpServer.listen({ port: PORT }, () => {
200
218
  env_1.logger.info(`🚀 Server ready at http://0.0.0.0:${PORT}/graphql`);
201
219
  env_1.logger.info(`🚀 Subscriptions ready at ws://0.0.0.0:${PORT}/graphql`);
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../server/server.ts"],"names":[],"mappings":";AAAA,4BAA4B;;;AAE5B,4DAA4D;AAC5D,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AACxB,OAAO,CAAC,GAAG,CAAC,kBAAkB,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,CAAA;AAEjD,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;AAEjE,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,YAAY,CAAA;AACnC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;AAE1B,2CAA6C;AAC7C,2EAAyF;AACzF,uEAA0G;AAC1G,8CAAoD;AAEpD,0DAA+B;AAC/B,qGAAiE;AACjE,8CAAiD;AACjD,+BAAmC;AACnC,sDAAqB;AACrB,4EAA0C;AAC1C,oEAAkC;AAClC,sEAAiC;AACjC,yFAAsE;AACtE,2BAAoC;AACpC,oDAAmB;AACnB,wDAAuB;AAEvB,6DAA4B;AAC5B,4DAA2B;AAE3B,6CAAgF;AAChF,qFAAoF;AAEpF,iEAA2D;AAC3D,sDAA6D;AAC7D,uCAMkB;AAClB,qCAAiC;AACjC,+CAAgD;AAEhD,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,KAAK,CAAC,EAAE;IACtC,YAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAA;IAE1C,iBAAiB;AACnB,CAAC,CAAC,CAAA;AAEF,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAE5B,IAAI,CAAC,MAAM,CAAC,MAAM,EA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EAAE,MAAM,EAAN,YAAM,EAAE,WAAW,EAAE,UAAU,EAAS,CAAC,CAAA;IAChG,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,SAAS,EAAE,CAAA","sourcesContent":["// ts-import-sorter: disable\n\n/* following 5 lines should be located in top of the file */\nconst OS = require('os')\nprocess.env.UV_THREADPOOL_SIZE = OS.cpus().length\n\nconsole.log('UV_THREADPOOL_SIZE', process.env.UV_THREADPOOL_SIZE)\n\nprocess.env.NODE_ENV = 'production'\nprocess.setMaxListeners(0)\n\nimport { ApolloServer } from '@apollo/server'\nimport { ApolloServerPluginDrainHttpServer } from '@apollo/server/plugin/drainHttpServer'\nimport { ApolloServerPluginLandingPageProductionDefault } from '@apollo/server/plugin/landingPage/default'\nimport { koaMiddleware } from '@as-integrations/koa'\n\nimport bytesFormat from 'bytes'\nimport graphqlUploadKoa from 'graphql-upload/graphqlUploadKoa.js'\nimport { useServer } from 'graphql-ws/lib/use/ws'\nimport { createServer } from 'http'\nimport Koa from 'koa'\nimport koaBodyParser from 'koa-bodyparser'\nimport koaStatic from 'koa-static'\nimport compose from 'koa-compose'\nimport { historyApiFallback } from 'koa2-connect-history-api-fallback'\nimport { WebSocketServer } from 'ws'\nimport co from 'co'\nimport http from 'http'\n\nimport cors from '@koa/cors'\nimport crypto from 'crypto'\n\nimport { config, loader, logger, orderedModuleNames } from '@things-factory/env'\nimport { initLicense, checkValidity } from '@things-factory/operato-license-checker'\n\nimport { GraphqlLocalClient } from './graphql-local-client'\nimport { databaseInitializer } from './initializers/database'\nimport {\n domainPrivateRouter,\n domainPublicRouter,\n globalPrivateRouter,\n globalPublicRouter,\n graphqlRouter\n} from './routers'\nimport { schema } from './schema'\nimport { domainMiddleware } from './middlewares'\n\nprocess.on('uncaughtException', error => {\n logger.error('uncaughtException: ', error)\n\n //process.exit(1)\n})\n\nconst args = require('args')\n\nargs.option('port', 'The port on which the app will be running', config.get('port', 3000))\n\nconst flags = args.parse(process.argv)\n\nconst path = require('path')\n\nconst PORT = (process.env.PORT = flags.port)\n\nconst requestBody = config.get('requestBody') || {}\n\nconst bodyParserOption = {\n formLimit: requestBody.formLimit || '10mb',\n jsonLimit: requestBody.jsonLimit || '10mb',\n textLimit: requestBody.textLimit || '10mb'\n}\n\nconst fileUpload = config.get('fileUpload') || {}\nconst fileUploadOption = {\n maxFileSize: bytesFormat.parse(fileUpload.maxFileSize) || bytesFormat.parse('10mb'),\n maxFiles: fileUpload.maxFiles || 10\n}\n\ninitLicense(config.get('licenseKey'))\n\n/* bootstrap */\nconst bootstrap = async () => {\n await databaseInitializer()\n\n const app = new Koa() as any\n app.proxy = true\n\n app.use(\n cors({\n origin: function (ctx) {\n return ctx.request.headers.origin || '*'\n },\n exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],\n maxAge: 5,\n credentials: true,\n /* allowMethods: ['GET', 'POST', 'DELETE'], -- use default */\n allowHeaders: ['Content-Type', 'Authorization', 'Accept']\n })\n )\n\n app.use(async (ctx, next) => {\n ctx.set('X-Content-Type-Options', 'nosniff')\n\n const { directives = {} } = config.get('CSP') || {}\n\n const nonce = crypto.randomBytes(16).toString('base64')\n ctx.state.nonce = nonce\n\n const cspHeader = Object.entries(directives as { [key: string]: string[] })\n .map(([key, value]) => `${key} ${value.join(' ')}`)\n .join('; ')\n\n ctx.set('Content-Security-Policy', cspHeader)\n\n await next()\n })\n\n var subscriptionMiddleware = []\n process.emit('bootstrap-module-subscription' as any, app, subscriptionMiddleware)\n\n const builtSchema = await schema()\n\n const httpServer = createServer(app.callback())\n const websocketServer = new WebSocketServer({\n server: httpServer,\n path: '/graphql'\n })\n\n // Save the returned server's info so we can shut down this server later\n const serverCleanup = useServer(\n {\n schema: builtSchema,\n context: async (ctx, msg, args) => {\n return ctx['context']\n },\n onConnect: async ctx => {\n var { extra, connectionParams } = ctx\n var { request } = extra\n\n if (((connectionParams['headers'] as any) || connectionParams)?.referer) {\n var url = new URL(((connectionParams['headers'] as any) || connectionParams).referer)\n var accessToken = url.searchParams.get('access_token')\n if (accessToken) {\n connectionParams['headers']['authorization'] = accessToken\n }\n }\n\n request.headers = {\n ...request.headers,\n ...(connectionParams['headers'] || (connectionParams as any))\n }\n\n var koacontext = await app.createContext(request, new http.ServerResponse(request))\n koacontext['state'] = {}\n\n /* in case connect error(like a authentication error) just throw exception */\n var middlewares = [domainMiddleware, ...subscriptionMiddleware]\n const fn = co.wrap(compose(middlewares))\n\n await fn(koacontext)\n\n return (ctx['context'] = koacontext)\n },\n onDisconnect(ctx, code, reason) {\n console.log('Disconnected!')\n },\n onError(ctx, msg, errors) {\n console.error(msg, errors)\n }\n },\n websocketServer\n )\n\n const server = new ApolloServer({\n schema: builtSchema,\n formatError: error => {\n logger.error(error)\n return error\n },\n introspection: true,\n csrfPrevention: true,\n plugins: [\n // Proper shutdown for the HTTP server.\n ApolloServerPluginDrainHttpServer({ httpServer }),\n // Proper shutdown for the WebSocket server.\n {\n async serverWillStart() {\n return {\n async drainServer() {\n await serverCleanup.dispose()\n }\n }\n }\n },\n // TODO make this landing page work\n ApolloServerPluginLandingPageProductionDefault({\n graphRef: 'my-graph-id@my-graph-variant',\n footer: false\n })\n ],\n cache: 'bounded'\n })\n\n await server.start()\n\n GraphqlLocalClient.init(builtSchema, app)\n\n orderedModuleNames.forEach(name => {\n const { initMiddlewares } = loader(name)\n initMiddlewares && initMiddlewares(app)\n })\n\n const render = require('@things-factory/ejs-remote')\n render(app, {\n root: '/views',\n host: `http://127.0.0.1:${PORT}`,\n layout: false,\n viewExt: 'html',\n cache: true,\n debug: false\n })\n\n app.use(koaBodyParser(bodyParserOption))\n\n /* routers */\n const ssoMiddlewares = []\n process.emit('bootstrap-collect-sso-middleware' as any, null, ssoMiddlewares)\n app.ssoMiddlewares = ssoMiddlewares\n\n process.emit('bootstrap-module-global-public-route' as any, app, globalPublicRouter)\n process.emit('bootstrap-module-global-private-route' as any, app, globalPrivateRouter)\n process.emit('bootstrap-module-domain-public-route' as any, app, domainPublicRouter)\n process.emit('bootstrap-module-domain-private-route' as any, app, domainPrivateRouter)\n\n app.use(checkValidity) /* Check the license after most of the context has been built */\n\n app\n .use(globalPublicRouter.routes())\n .use(globalPublicRouter.allowedMethods())\n .use(globalPrivateRouter.routes())\n .use(globalPrivateRouter.allowedMethods())\n .use(domainPublicRouter.routes())\n .use(domainPublicRouter.allowedMethods())\n .use(domainPrivateRouter.routes())\n .use(domainPrivateRouter.allowedMethods())\n\n /* Graphql Upload's multipart/form-data handling affects the restful file upload feature, so it should be placed after the routers configuration. */\n app.use(graphqlUploadKoa(fileUploadOption))\n\n graphqlRouter.post(\n '/graphql',\n koaMiddleware(server, {\n context: async ({ ctx }) => ctx\n })\n )\n app.use(graphqlRouter.routes())\n app.use(graphqlRouter.allowedMethods())\n\n /* should follow this order : history-fallback => koaStatic */\n app.use(historyApiFallback({ whiteList: [] }))\n\n app.use(\n koaStatic(path.join(process.cwd(), 'dist-app'), {\n index: 'index.html'\n })\n )\n\n httpServer.listen({ port: PORT }, () => {\n logger.info(`🚀 Server ready at http://0.0.0.0:${PORT}/graphql`)\n logger.info(`🚀 Subscriptions ready at ws://0.0.0.0:${PORT}/graphql`)\n\n process.emit('bootstrap-module-start' as any, { app, config, builtSchema, httpServer } as any)\n })\n}\n\nbootstrap()\n"]}
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../server/server.ts"],"names":[],"mappings":";AAAA,4BAA4B;;;AAE5B,4DAA4D;AAC5D,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AACxB,OAAO,CAAC,GAAG,CAAC,kBAAkB,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,CAAA;AAEjD,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;AAEjE,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,YAAY,CAAA;AACnC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;AAE1B,2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*/\nconst OS = require('os')\nprocess.env.UV_THREADPOOL_SIZE = OS.cpus().length\n\nconsole.log('UV_THREADPOOL_SIZE', process.env.UV_THREADPOOL_SIZE)\n\nprocess.env.NODE_ENV = 'production'\nprocess.setMaxListeners(0)\n\nimport { ApolloServer } from '@apollo/server'\nimport { ApolloServerPluginDrainHttpServer } from '@apollo/server/plugin/drainHttpServer'\nimport { ApolloServerPluginLandingPageProductionDefault } from '@apollo/server/plugin/landingPage/default'\nimport { koaMiddleware } from '@as-integrations/koa'\n\nimport bytesFormat from 'bytes'\nimport graphqlUploadKoa from 'graphql-upload/graphqlUploadKoa.js'\nimport { useServer } from 'graphql-ws/lib/use/ws'\nimport { createServer } from 'http'\nimport Koa from 'koa'\nimport koaBodyParser from 'koa-bodyparser'\nimport koaStatic from 'koa-static'\nimport compose from 'koa-compose'\nimport { historyApiFallback } from 'koa2-connect-history-api-fallback'\nimport { WebSocketServer } from 'ws'\nimport co from 'co'\nimport http from 'http'\n\nimport cors from '@koa/cors'\nimport crypto from 'crypto'\n\nimport { config, loader, logger, orderedModuleNames } from '@things-factory/env'\nimport { initLicense, checkValidity } from '@things-factory/operato-license-checker'\n\nimport { GraphqlLocalClient } from './graphql-local-client'\nimport { databaseInitializer } from './initializers/database'\nimport {\n domainPrivateRouter,\n domainPublicRouter,\n globalPrivateRouter,\n globalPublicRouter,\n graphqlRouter\n} from './routers'\nimport { schema } from './schema'\nimport { domainMiddleware } from './middlewares'\n\nprocess.on('uncaughtException', error => {\n logger.error('uncaughtException: ', error)\n\n //process.exit(1)\n})\n\nconst args = require('args')\n\nargs.option('port', 'The port on which the app will be running', config.get('port', 3000))\n\nconst flags = args.parse(process.argv)\n\nconst path = require('path')\n\nconst PORT = (process.env.PORT = flags.port)\n\nconst requestBody = config.get('requestBody') || {}\n\nconst bodyParserOption = {\n formLimit: requestBody.formLimit || '10mb',\n jsonLimit: requestBody.jsonLimit || '10mb',\n textLimit: requestBody.textLimit || '10mb'\n}\n\nconst fileUpload = config.get('fileUpload') || {}\nconst fileUploadOption = {\n maxFileSize: bytesFormat.parse(fileUpload.maxFileSize) || bytesFormat.parse('10mb'),\n maxFiles: fileUpload.maxFiles || 10\n}\n\ninitLicense(config.get('licenseKey'))\n\n/* bootstrap */\nconst bootstrap = async () => {\n await databaseInitializer()\n\n const app = new Koa() as any\n app.proxy = true\n\n app.use(\n cors({\n origin: function (ctx) {\n return ctx.request.headers.origin || '*'\n },\n exposeHeaders: ['WWW-Authenticate', 'Server-Authorization'],\n maxAge: 5,\n credentials: true,\n /* allowMethods: ['GET', 'POST', 'DELETE'], -- use default */\n allowHeaders: ['Content-Type', 'Authorization', 'Accept']\n })\n )\n\n app.use(async (ctx, next) => {\n ctx.set('X-Content-Type-Options', 'nosniff')\n\n const { directives = {} } = config.get('CSP') || {}\n\n const nonce = crypto.randomBytes(16).toString('base64')\n ctx.state.nonce = nonce\n\n const cspHeader = Object.entries(directives as { [key: string]: string[] })\n .map(([key, value]) => `${key} ${value.join(' ')}`)\n .join('; ')\n\n ctx.set('Content-Security-Policy', cspHeader)\n\n await next()\n })\n\n var subscriptionMiddleware = []\n process.emit('bootstrap-module-subscription' as any, app, subscriptionMiddleware)\n\n const builtSchema = await schema()\n\n const httpServer = createServer(app.callback())\n const websocketServer = new WebSocketServer({\n server: httpServer,\n path: '/graphql'\n })\n\n // Save the returned server's info so we can shut down this server later\n const serverCleanup = useServer(\n {\n schema: builtSchema,\n context: async (ctx, msg, args) => {\n return ctx['context']\n },\n onConnect: async ctx => {\n var { extra, connectionParams } = ctx\n var { request } = extra\n\n if (((connectionParams['headers'] as any) || connectionParams)?.referer) {\n var url = new URL(((connectionParams['headers'] as any) || connectionParams).referer)\n var accessToken = url.searchParams.get('access_token')\n if (accessToken) {\n connectionParams['headers']['authorization'] = accessToken\n }\n }\n\n request.headers = {\n ...request.headers,\n ...(connectionParams['headers'] || (connectionParams as any))\n }\n\n var koacontext = await app.createContext(request, new http.ServerResponse(request))\n koacontext['state'] = {}\n\n /* in case connect error(like a authentication error) just throw exception */\n var middlewares = [domainMiddleware, ...subscriptionMiddleware]\n const fn = co.wrap(compose(middlewares))\n\n await fn(koacontext)\n\n return (ctx['context'] = koacontext)\n },\n onDisconnect(ctx, code, reason) {\n console.log('Disconnected!')\n },\n onError(ctx, msg, errors) {\n console.error(msg, errors)\n }\n },\n websocketServer\n )\n\n const server = new ApolloServer({\n schema: builtSchema,\n formatError: error => {\n logger.error(error)\n return error\n },\n introspection: true,\n csrfPrevention: true,\n plugins: [\n // Proper shutdown for the HTTP server.\n ApolloServerPluginDrainHttpServer({ httpServer }),\n // Proper shutdown for the WebSocket server.\n {\n async serverWillStart() {\n return {\n async drainServer() {\n await serverCleanup.dispose()\n }\n }\n }\n },\n // TODO make this landing page work\n ApolloServerPluginLandingPageProductionDefault({\n graphRef: 'my-graph-id@my-graph-variant',\n footer: false\n })\n ],\n cache: 'bounded'\n })\n\n await server.start()\n\n GraphqlLocalClient.init(builtSchema, app)\n\n orderedModuleNames.forEach(name => {\n const { initMiddlewares } = loader(name)\n initMiddlewares && initMiddlewares(app)\n })\n\n const render = require('@things-factory/ejs-remote')\n render(app, {\n root: '/views',\n host: `http://127.0.0.1:${PORT}`,\n layout: false,\n viewExt: 'html',\n cache: true,\n debug: false\n })\n\n app.use(koaBodyParser(bodyParserOption))\n\n /* routers */\n const ssoMiddlewares = []\n process.emit('bootstrap-collect-sso-middleware' as any, null, ssoMiddlewares)\n app.ssoMiddlewares = ssoMiddlewares\n\n process.emit('bootstrap-module-global-public-route' as any, app, globalPublicRouter)\n process.emit('bootstrap-module-global-private-route' as any, app, globalPrivateRouter)\n process.emit('bootstrap-module-domain-public-route' as any, app, domainPublicRouter)\n process.emit('bootstrap-module-domain-private-route' as any, app, domainPrivateRouter)\n\n app.use(checkValidity) /* Check the license after most of the context has been built */\n\n app\n .use(globalPublicRouter.routes())\n .use(globalPublicRouter.allowedMethods())\n .use(globalPrivateRouter.routes())\n .use(globalPrivateRouter.allowedMethods())\n .use(domainPublicRouter.routes())\n .use(domainPublicRouter.allowedMethods())\n .use(domainPrivateRouter.routes())\n .use(domainPrivateRouter.allowedMethods())\n\n /* Graphql Upload's multipart/form-data handling affects the restful file upload feature, so it should be placed after the routers configuration. */\n app.use(graphqlUploadKoa(fileUploadOption))\n\n graphqlRouter.post(\n '/graphql',\n koaMiddleware(server, {\n context: async ({ ctx }) => ctx\n })\n )\n app.use(graphqlRouter.routes())\n app.use(graphqlRouter.allowedMethods())\n\n /* should follow this order : history-fallback => koaStatic */\n app.use(historyApiFallback({ whiteList: [] }))\n\n app.use(\n koaStatic(path.join(process.cwd(), 'dist-app'), {\n index: 'index.html'\n })\n )\n\n // Set keep-alive timeout from configuration or fallback to default (65000ms).\n // The keepAliveTimeout determines how long the server will keep an idle connection\n // alive before closing it.\n const keepAliveTimeout = config.get('keepAliveTimeout', 65000)\n\n // Apply the configured keep-alive timeout to the server. If no configuration is\n // provided, default to 65000ms (65 seconds). In the context of an external load balancer,\n // this timeout is critical for maintaining persistent connections between the load\n // balancer and the server. Setting a sufficiently long keepAliveTimeout minimizes\n // the need to constantly re-establish TCP connections, improving efficiency and\n // reducing connection overhead.\n httpServer.keepAliveTimeout = keepAliveTimeout || 65000\n\n // Set headersTimeout to be 1000ms (1 second) longer than keepAliveTimeout.\n // This ensures the server has sufficient time to receive headers from the client\n // before closing the connection, preventing premature disconnections. In the context\n // of a load balancer, this ensures that if the load balancer is sending headers\n // slowly (due to network delays or other factors), the connection isn't closed\n // before the headers are fully transmitted.\n httpServer.headersTimeout = keepAliveTimeout + 1000\n\n httpServer.listen({ port: PORT }, () => {\n logger.info(`🚀 Server ready at http://0.0.0.0:${PORT}/graphql`)\n logger.info(`🚀 Subscriptions ready at ws://0.0.0.0:${PORT}/graphql`)\n\n process.emit('bootstrap-module-start' as any, { app, config, builtSchema, httpServer } as any)\n })\n}\n\nbootstrap()\n"]}