Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring implicit file extensions in FileService #4542

Closed
ikhoon opened this issue Nov 18, 2022 · 0 comments · Fixed by #5806
Closed

Allow configuring implicit file extensions in FileService #4542

ikhoon opened this issue Nov 18, 2022 · 0 comments · Fixed by #5806

Comments

@ikhoon
Copy link
Contributor

ikhoon commented Nov 18, 2022

Some front web frameworks such as Next.js generates HTML files according to directory paths. If /pages/app/projects.tsx is specified in Next.js pages folder, a Next.js server serves on the tsx file on /app/projects URL.

To use the tsx file without a Next.js server, it is possible to use next export that converts /pages/app/projects.tsx into /app/projects.html or /app/projects/index.html if trailingSlash option is enabled. That being said, FileService needs an explicit file extension to search for the desired file if the path does not have a trailing slash. The path /app/projects served in the Next.js server no longer works with FileService which is able to serve only /app/projects.html or /app/projects/ for /app/projects/index.html.

If FileService supported implicit file extensions, we would serve HTML file like REST APIs.

FileService
  .builder(Paths.get("/static/resources"))
  // Try to append html and find a matching file
  // if the original path does not exist.
  .autoFileExtension("html")
ikhoon added a commit to ikhoon/centraldogma that referenced this issue Nov 18, 2022
Motivation:

Next.js generates index.html files under the target paths when
`trailingSlash` option is enabled. Additionally, `/` is automatically
added to a routing path.
https://nextjs.org/docs/api-reference/next.config.js/trailing-slash

Note:

This PR is a temporary workaround to respond to trailing slashs properly.
The URLs will be reverted and `trailingSlash` option is disabled when
line/armeria#4542 is resolved.

Modifications:

- Appended `/` to URLs related to authentication.
- Remove the legacy auth file service to avoid path conllisions.

Result:

- Users can login with Shiro authentication.
ikhoon added a commit to line/centraldogma that referenced this issue Nov 18, 2022
Motivation:

Next.js generates index.html files under the target paths when `trailingSlash` option is enabled. Additionally, `/` is automatically added to a routing path.
https://nextjs.org/docs/api-reference/next.config.js/trailing-slash

Note:

This PR is a temporary workaround to respond to trailing slashs properly. The URLs will be reverted and `trailingSlash` option is disabled when line/armeria#4542 is resolved.

Modifications:

- Appended `/` to URLs related to authentication.
- Remove the legacy auth file service to avoid path collisions.

Result:

- Users can login with Shiro authentication.
ikhoon added a commit to ikhoon/centraldogma that referenced this issue Apr 10, 2023
Motivation:

Next.js generates index.html files under the target paths when `trailingSlash` option is enabled. Additionally, `/` is automatically added to a routing path.
https://nextjs.org/docs/api-reference/next.config.js/trailing-slash

Note:

This PR is a temporary workaround to respond to trailing slashs properly. The URLs will be reverted and `trailingSlash` option is disabled when line/armeria#4542 is resolved.

Modifications:

- Appended `/` to URLs related to authentication.
- Remove the legacy auth file service to avoid path collisions.

Result:

- Users can login with Shiro authentication.
ikhoon added a commit to ikhoon/centraldogma that referenced this issue Apr 20, 2023
Motivation:

Next.js generates index.html files under the target paths when `trailingSlash` option is enabled. Additionally, `/` is automatically added to a routing path.
https://nextjs.org/docs/api-reference/next.config.js/trailing-slash

Note:

This PR is a temporary workaround to respond to trailing slashs properly. The URLs will be reverted and `trailingSlash` option is disabled when line/armeria#4542 is resolved.

Modifications:

- Appended `/` to URLs related to authentication.
- Remove the legacy auth file service to avoid path collisions.

Result:

- Users can login with Shiro authentication.
ikhoon added a commit to ikhoon/armeria that referenced this issue Jul 9, 2024
Motivation:

I personally prefer clean URL patterns without a trailing slash.
`/app/projects` is prefered over `/app/projects/`.  If I built
`/app/projects` with a Javascript framework, `/app/projects/index.html`
or `/app/projects.html` may be exported by the framework.

In `FileService`, `/app/projects/index.html` can be served by
`/app/projects/` path, but cannot be found by `/app/projects`. Handling
trailing slash is tricky and difficult to modify.

Alternatively, I propose an option that appends an extension if there is
no file for the request path. For example, a request sent to
`/app/projects` also finds `/app/projects.[ext]` as a fallback.

Relate links:

- line#4542
- line#1655
- https://ktor.io/docs/server-static-content.html#extensions

Modifications:

- Allow configuring `fileExtensions()` via `FileServiceBuilder`
- Find a file with fallback extensions if missing.

Result:

You can now set fallback file extensions to look up files in
`FileService`.

```java
FileService
  .builder(rootDir)
  .fileExtensions("html", "txt")
  ...
```
ikhoon added a commit to ikhoon/armeria that referenced this issue Jul 9, 2024
Motivation:

I personally prefer clean URL patterns without a trailing slash.
`/app/projects` is prefered over `/app/projects/`.  If I built
`/app/projects` with a Javascript framework, `/app/projects/index.html`
or `/app/projects.html` may be exported by the framework.

In `FileService`, `/app/projects/index.html` can be served by
`/app/projects/` path, but cannot be found by `/app/projects`. Handling
trailing slash is tricky and difficult to modify.

Alternatively, I propose an option that appends an extension if there is
no file for the request path. For example, a request sent to
`/app/projects` also finds `/app/projects.[ext]` as a fallback.

Relate links:

- line#4542
- line#1655
- https://ktor.io/docs/server-static-content.html#extensions

Modifications:

- Allow configuring `fileExtensions()` via `FileServiceBuilder`
- Find a file with fallback extensions if missing.

Result:

You can now set fallback file extensions to look up files in
`FileService`.

```java
FileService
  .builder(rootDir)
  .fileExtensions("html", "txt")
  ...
```
ikhoon added a commit that referenced this issue Jul 16, 2024
Motivation:

I prefer clean URL patterns without a trailing slash so `/app/projects`
is preferred over `/app/projects/`. If I built `/app/projects` with a
Javascript framework, `/app/projects/index.html` or `/app/projects.html`
may be exported by the framework which is a common feature.

In `FileService`, `/app/projects/index.html` can be served by
`/app/projects/` path, but cannot be found by `/app/projects`. A
trailing slash `/` can be converted into `/index.html` or an auto index
page. As some fallback logics are already implemented, I didn't want to
add a new fallback option for a trailing slash.

Alternatively, I propose an option that appends an extension if there is
no file for the request path. For example, a request sent to
`/app/projects` also finds `/app/projects.[ext]` as a fallback.

Related links:

- #4542
- #1655
- https://ktor.io/docs/server-static-content.html#extensions

Modifications:

- Allow configuring `fallbackFileExtensions()` via `FileServiceBuilder`
- Find a file with fallback extensions if missing.

Result:

- You can now set fallback file extensions to look up files in
`FileService`.

```java
FileService
  .builder(rootDir)
  .fallbackFileExtensions("html", "txt")
  ...
```
- Closes #4542
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant