如何从loopback应用中删除所有前端文件

发布于 2025-01-25 01:36:50 字数 139 浏览 3 评论 0 原文

在回环API开发时,默认 LP4 App 命令非常方便地生成一个带有Swagger API Explorer的简单着陆页。

但是我不想完成这个。在代码中,我在哪里禁用自托管页面,以及我应该删除哪些文件以删除项目中的无关文件?

While developing on a loopback api it is very convenient that the default lp4 app command generates a simple landing page with a swagger api explorer.

But I don't want this when I am finished. where in the code do I disable the self hosted pages, and which files should I delete to remove irrelevant files in my project?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你对谁都笑 2025-02-01 01:36:50

4 您可能需要单独禁用/删除的工件:

  1. 默认/登录页面:链接到 OpenAPI的默认页面.json 和API资源管理器。
  2. 外部主持的REST Explorer重定向:/Swagger>/Swagger-ui /explorer 重定向到托管在其他地方的REST Explorer(例如=“ https://explorer.loopback.io” rel =“ nofollow noreferrer”> https://explorer.loopback.io )。
  3. 自托管REST Explorer: /explorer 提供的REST Explorer。默认情况下,优先考虑/explorer 路径的托管REST Explorer重定向。
  4. OpenAPI规格端点: OpenAPI 3.0 Spec opt /popenapi.json 默认情况下。

尽管可以完全遵循此处的说明,以便在大多数Loopback 4项目中都遵循,但更多的定制项目可能会有某些内容(例如应用程序或组件配置)。


删除默认/着陆页:

  1. 删除 public 目录

  2. src/application.ts

    中删除以下行

      //设置默认主页
    this.static('/',path.join(__ dirname,'../public'));
     

以通过配置禁用外部托管的REST Explorer:

  1. src/index.ts ,配置 config.rest.apiexplorer.disabled

      const config = {
      休息: {
        apiexplorer:{
          禁用:是的,
        },,
      },,
    };
     


完全删除自托管REST Explorer:

  1. 删除以下来自 application.ts 的行:

      // customize @loopback/rest-explorer配置
    this.configure(RESTEXPLORERBINDINGS.COMPONENT).to({
      路径:'/explorer',,
    });
    this.component(retexplorerComponent);
     
  2. application.ts

通过配置禁用OpenAPI Spec端点:

  1. in src/index.ts.ts ,配置 config.rest.openapispec.disabled

      const config = {
      休息: {
        OpenApispec:{
          禁用:是的,
        },,
      },,
    };
     

请注意,禁用OpenAPI规格端点会阻止REST Exploter在依赖其依赖的情况下正常工作Web浏览器可访问的OpenAPI规格。

禁用Opanapi Spec端点不会从TypeScript中禁用对OpenAPI规格的访问,也不会影响AJV验证。

参考

  • =“ https://loopback.io/doc/en/lb4/self-host-rest-rest-api-explorer.html#disable-self-host-hosted-api-explorer” rel =“ nofollow noreferrer”> htttps:htttps:// loopback .io/doc/en/lb4/Self-hosted-rest-api-explorer.html#disable-self-hosted-api-explorer

There are 4 artifacts that you may want to individually disabled/removed:

  1. Default / landing page: The default page that links to openapi.json and the API explorer.
  2. Externally-hosted REST explorer redirect: A redirect from /swagger-ui and /explorer to a REST explorer that's hosted elsewhere (e.g. https://explorer.loopback.io).
  3. Self-hosted REST explorer: A REST explorer served at /explorer. Takes precedence over hosted REST explorer redirect for /explorer path by default.
  4. OpenAPI spec endpoint: The OpenAPI 3.0 spec hosted at /openapi.json by default.

Although the instructions here can be followed exactly for majority of LoopBack 4 projects, more customised projects may have certain things (e.g. application or component configuration) moved around.


To remove the default / landing page:

  1. Remove the public directory

  2. Remove the following lines from src/application.ts:

    // Set up default home page
    this.static('/', path.join(__dirname, '../public'));
    

To disable externally-hosted REST explorer through configuration:

  1. In src/index.ts, configure config.rest.apiExplorer.disabled:

    const config = {
      rest: {
        apiExplorer: {
          disabled: true,
        },
      },
    };
    

To completely remove self-hosted REST explorer:

  1. Remove the following lines from application.ts:

    // Customize @loopback/rest-explorer configuration here
    this.configure(RestExplorerBindings.COMPONENT).to({
      path: '/explorer',
    });
    this.component(RestExplorerComponent);
    
  2. Uninstall @loopback/rest-explorer


To disable the OpenAPI spec endpoint through configuration:

  1. In src/index.ts, configure config.rest.openApiSpec.disabled:

    const config = {
      rest: {
        openApiSpec: {
          disabled: true,
        },
      },
    };
    

Note that disabling the OpenAPI spec endpoint would prevent the REST explorers from working correctly as they are dependent on an web browser-accessible OpenAPI spec.

Disabling the OpanAPI spec endpoint does not disable access to the OpenAPI spec from within TypeScript nor does it affect AJV validation.

References

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文