Skip to content

index.ts is different when created via Appsody vs lb4 app #6781

Description

@norricorp

Steps to reproduce

Run appsody init nodejs-loopback and compare with index.ts with project created with lb4 app

Current Behavior

appsody created index.ts

export async function main(config: ApplicationConfig = {}) {
  const app = new DemoApplication(config);
  await app.boot();
  await app.start();

  const url = app.restServer.url;
  console.log(`Server is running at ${url}`);
  console.log(`Try ${url}/ping`);

  return app;
}

lb4 created index.ts (comments removed)

export async function main(options: ApplicationConfig = {}) {
  const app = new TestApplication(options);
  await app.boot();
  await app.start();

  const url = app.restServer.url;
  console.log(`Server is running at ${url}`);
  console.log(`Try ${url}/ping`);

  return app;
}

if (require.main === module) {
  // Run the application
  const config = {
    rest: {
      port: +(process.env.PORT ?? 3000),
      host: process.env.HOST,
      gracePeriodForClose: 5000, // 5 seconds
      openApiSpec: {
        // useful when used with OpenAPI-to-GraphQL to locate your application
        setServersFromRequest: true,
      },
    },
  };
  main(config).catch(err => {
    console.error('Cannot start the application.', err);
    process.exit(1);
  });
}

Expected Behavior

For them to be the same?

Link to reproduction sandbox

Additional information

$ node -e 'console.log(process.platform, process.arch, process.versions.node)'
linux x64 12.19.0
$ npm ls --prod --depth 0 | grep loopback
nodejs-loopback-scaffold@1.0.0 /home/jnorris/loopback4/todolist
├── @loopback/boot@3.0.2
├── @loopback/context@3.12.0
├── @loopback/core@2.11.0
├── @loopback/openapi-v3@5.0.0
├── @loopback/repository@3.1.0
├── @loopback/rest@8.0.0
├── @loopback/rest-explorer@3.0.2
├── @loopback/service-proxy@3.0.2

This arose because I needed to configure CORS so as to work with a colocated gridsome server. Then I noticed that the appsody code did not have the required code to amend.

Putting CORS aside, both appsody and lb4 generated apps work with curl. The only difference is that appsody will allow access from outside of the machine, lb4 will only allow access via localhost.

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions