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

EmbeddedFilesEndpoint not working for index.html in subdirectory #824

Open
czy-29 opened this issue May 29, 2024 · 2 comments · May be fixed by #825
Open

EmbeddedFilesEndpoint not working for index.html in subdirectory #824

czy-29 opened this issue May 29, 2024 · 2 comments · May be fixed by #825
Labels
bug Something isn't working

Comments

@czy-29
Copy link

czy-29 commented May 29, 2024

I have the following two files at the same level of Cargo.toml:

static/index.html
static/test/index.html

Then I wrote the following code:

use poem::{endpoint::EmbeddedFilesEndpoint, listener::TcpListener, Route, Server};
use rust_embed::RustEmbed;

#[derive(RustEmbed)]
#[folder = "static"]
pub struct Static;

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
    if std::env::var_os("RUST_LOG").is_none() {
        std::env::set_var("RUST_LOG", "poem=debug");
    }
    tracing_subscriber::fmt::init();

    let app = Route::new().nest("/static", EmbeddedFilesEndpoint::<Static>::new());
    Server::new(TcpListener::bind("0.0.0.0:3000"))
        .run(app)
        .await
}

When I visit http://127.0.0.1:3000/static, the program can get static/index.html correctly.
When I visit http://127.0.0.1:3000/static/test/index.html, the program can also get static/test/index.html correctly.
But when I visit http://127.0.0.1:3000/static/test and http://127.0.0.1:3000/static/test/, I get 404 errors. But they should be correctly redirected to static/test/index.html just like static/index.html.
I think this is a bug.

@czy-29 czy-29 added the bug Something isn't working label May 29, 2024
@czy-29
Copy link
Author

czy-29 commented May 29, 2024

中文版本:
标题:EmbeddedFilesEndpoint对于子目录中的index.html不工作

我在Cargo.toml的相同层级下有如下两个文件:

static/index.html
static/test/index.html

然后我写了如下代码:

use poem::{endpoint::EmbeddedFilesEndpoint, listener::TcpListener, Route, Server};
use rust_embed::RustEmbed;

#[derive(RustEmbed)]
#[folder = "static"]
pub struct Static;

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
    if std::env::var_os("RUST_LOG").is_none() {
        std::env::set_var("RUST_LOG", "poem=debug");
    }
    tracing_subscriber::fmt::init();

    let app = Route::new().nest("/static", EmbeddedFilesEndpoint::<Static>::new());
    Server::new(TcpListener::bind("0.0.0.0:3000"))
        .run(app)
        .await
}

当我访问http://127.0.0.1:3000/static时,程序可以正确地获取static/index.html
当我访问http://127.0.0.1:3000/static/test/index.html时,程序也可以正确地获取static/test/index.html
但是当我访问http://127.0.0.1:3000/static/test以及 http://127.0.0.1:3000/static/test/时,均得到404错误。但它们本应该像static/index.html一样,被正确地重定向到static/test/index.html上。
我认为这是一个bug。

@czy-29
Copy link
Author

czy-29 commented May 30, 2024

I submitted a PR to fix this bug, welcome to review: #825
我自己提交了修复本bug的pr,欢迎大佬们review:#825

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant