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

关于反代的问题 #407

Open
wang666233-art opened this issue Jan 19, 2025 · 1 comment
Open

关于反代的问题 #407

wang666233-art opened this issue Jan 19, 2025 · 1 comment
Labels
question Further information is requested

Comments

@wang666233-art
Copy link

wang666233-art commented Jan 19, 2025

请问反代该怎么配置,我想把这个api用到pixiv-viewer上,用caddy进行反代,如果只是这样配置的话

xxx.com {
    tls xxx@gmail.com
    reverse_proxy 127.0.0.1:8089
}

会连接失败,似乎是需要配置跨域。网上查了一下后将配置修改为

xxx.com{
    tls xxx@gmail.com
    reverse_proxy 127.0.0.1:8089 {
        header_up Host {upstream_hostport}
    }

# 指定一个匹配 OPTIONS 请求方法的匹配器
@cors_preflight {
    method OPTIONS
    header Origin *
    }

# 处理这个匹配器,返回 204,并且允许跨域
    handle @cors_preflight {
        respond 204
        header Access-Control-Allow-Origin "*"
        header Access-Control-Allow-Methods "GET, POST, OPTIONS"
        header Access-Control-Allow-Headers "*"
    }

# 设置允许跨域的响应头
    header {
        Access-Control-Allow-Origin *
        Access-Control-Allow-Methods "GET, POST, OPTIONS"
    }
}

但这样配置后也有一些问题,比如小说加载不出正文,推荐和发现模块不显示。api地址换成您的api.obfs.dev则没有这些问题,请问您是怎么配置反代的?

@mnixry mnixry added the question Further information is requested label Jan 21, 2025
@mnixry
Copy link
Member

mnixry commented Jan 21, 2025

不需要在反代层设置 CORS,HibiAPI 本身有配置

GENERAL_SERVER_CORS_ORIGINS=["*"]

应该就行

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Development

No branches or pull requests

2 participants