From 4283a98ea0cbdba26f697a1bf0f899e59add9261 Mon Sep 17 00:00:00 2001 From: Mario Estrada Date: Mon, 22 Oct 2018 18:51:23 -0600 Subject: [PATCH] refactor(cli): use options to specify app port and openapi server --- packages/cli/generators/app/templates/index.js.ejs | 12 +++++++++++- .../test/integration/generators/app.integration.js | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/cli/generators/app/templates/index.js.ejs b/packages/cli/generators/app/templates/index.js.ejs index 12484ccad1c7..78018fcf4412 100644 --- a/packages/cli/generators/app/templates/index.js.ejs +++ b/packages/cli/generators/app/templates/index.js.ejs @@ -4,7 +4,17 @@ module.exports = application; if (require.main === module) { // Run the application - application.main().catch(err => { + const config = { + rest: { + port: +process.env.PORT || 3000, + host: process.env.HOST || 'localhost', + openApiSpec: { + // useful when used with OASGraph to locate your application + setServersFromRequest: true, + }, + }, + }; + application.main(config).catch(err => { console.error('Cannot start the application.', err); process.exit(1); }); diff --git a/packages/cli/test/integration/generators/app.integration.js b/packages/cli/test/integration/generators/app.integration.js index ca2f34e859a7..2f04e3dc7d6d 100644 --- a/packages/cli/test/integration/generators/app.integration.js +++ b/packages/cli/test/integration/generators/app.integration.js @@ -40,6 +40,10 @@ describe('app-generator specific files', () => { assert.fileContent('src/application.ts', /constructor\(/); assert.fileContent('src/application.ts', /this.projectRoot = __dirname/); + assert.file('index.js'); + assert.fileContent('index.js', /openApiSpec: {/); + assert.fileContent('index.js', /setServersFromRequest: true/); + assert.file('src/index.ts'); assert.fileContent('src/index.ts', /new MyAppApplication/); assert.fileContent('src/index.ts', /await app.start\(\);/);