loopbackio / loopbackio/loopback-next

Sugar API for defining URL redirects

オープン
#2,022 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

API Explorer developer-experience feature good first issue REST
主要言語
TypeScript
スター
5.1k
フォーク
1.1k
平均マージ
2日 21時間
マージ済み PR(30日)
27

説明

This is a follow-up for https://github.com/strongloop/loopback-next/pull/2014.

When using LB4+ to serve HTML pages, it's useful to add a trailing slash to the URL when serving a folder, for example redirect /explorer to /explorer/. Without this redirect, relative URLs to assets like CSS & JS files are incorrectly resolved. For example, when served from /explorer, relative links like ./swagger-ui.css are resolved in the parent directory, e.g. /swagger-ui.css instead of /explorer/swagger-ui.css.

Right now, a redirect can be implemented using a controller route that's hidden from the documentation and uses HTTP response object to send back the redirect. Such solution requires a lot of code and feels a bit hacky.

Let's make redirects a first-class feature in LB4 and provide a high-level API that's easy to use.

For example:

restApp.redirect('/explorer', '/explorer/');
restServer.redirect('/explorer', '/explorer/');

Under the hood, this can be implemented as a new Route class, for example:

app.route(new RedirectRoute('/explorer', '/explorer/'));

A mock-up implementation of RedirectRoute:

export class RedirectRoute implements RouteEntry, ResolvedRoute {
  // ResolvedRoute API
  readonly pathParams: PathParameterValues = [];
  readonly schemas: SchemasObject = {};

  // RouteEntry implementation
  readonly verb: string = 'get';
  readonly get path(): string { return this.sourcePath; }
  // ...

  constructor(
    public readonly sourcePath: string, 
    public readonly targetPath: string, 
    public statusCode: number = 303,
  ) {
    this.path = sourcePath;
  }

  async invokeHandler(
    {response}: RequestContext,
    args: OperationArgs,
  ): Promise<OperationRetval> {
    response.redirect(this.statusCode, this.targetPath);
  }

  // ...
}

Acceptance criteria

https://github.com/strongloop/loopback-next/pull/2512

  • The implementation, including unit/integration/acceptance tests
    • Most of the tests should be written for RestServer.
    • Add one or few tests for RestApplication at integration or acceptance level, just to ensure the new RestApplication API is covered.
  • Documentation

TODO

  • Redirect to dynamically computed location (see the discussion below)
  • Search for all places calling .redirect( and consider updating them to use the new route and/or the new RestServer/RestApplication sugar APIs. E.g. REST API Explorer.
    • Redirect to externally hosted swagger-ui
    • Redirect from /explorer to /explorer/
  • Redirect to a location that's full URL (http://example.com) instead of a local path (/home). The trick is to skip appending basePath.
  • Honor req.baseUrl when the LB4 app is mounted on an external Express application.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、参照されている pull request 2512 と、issue に記載されている RestServer および RestApplication API を確認します。リダイレクトの動作に関する単体テスト、統合テスト、受け入れテストを確認し、その後、残っている TODOs と文書化された実装を比較して、まだ対応すべき作業が残っているかどうかを判断します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
node.js, typescript
領域
api, backend
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。