diff --git a/examples/hello-world/index.js b/examples/hello-world/index.js index 23bcda999e32..2800ea495ada 100644 --- a/examples/hello-world/index.js +++ b/examples/hello-world/index.js @@ -9,7 +9,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/examples/soap-calculator/index.js b/examples/soap-calculator/index.js index 12484ccad1c7..78018fcf4412 100644 --- a/examples/soap-calculator/index.js +++ b/examples/soap-calculator/index.js @@ -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/examples/todo-list/index.js b/examples/todo-list/index.js index f60622546c19..d9b161f4c190 100644 --- a/examples/todo-list/index.js +++ b/examples/todo-list/index.js @@ -9,6 +9,16 @@ module.exports = application; if (require.main === module) { // Run the application + 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().catch(err => { console.error('Cannot start the application.', err); process.exit(1); diff --git a/examples/todo/index.js b/examples/todo/index.js index 08ea81118b44..35bffe4aca7a 100644 --- a/examples/todo/index.js +++ b/examples/todo/index.js @@ -9,7 +9,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/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\(\);/);