我们目前正在使用Github页面作为简单的API模拟服务器。我们将所有模拟文件放在docs/
下,并简单地GET username.github.io/project/api/someAPI
来检索数据。但是,默认情况下,对于没有扩展名的文件,Github Pages返回的Content-Type为application/octet-stream
而不是application/json
,因此我们的前端代码在解析结果时会抛出错误。
我想知道有没有办法在Github页面上为没有扩展名的文件更改返回的Content-Type?
答案 0 :(得分:1)
您不能在每个文件或每个存储库的基础上指定自定义 MIME 类型
根据实验,您可以创建 @Cacheable(value = "token")
public String getToken(String apiKey, String email, String senha) {
System.out.println("no cache");
return webClient.post()
.uri("my/uri")
.header("Api-Key", apiKey)
.accept(MediaType.APPLICATION_JSON)
.bodyValue(new LoginObj(email, senha))
.retrieve()
.bodyToMono(JsonNode.class)
.block()
.get("token")
.asText();
}
,这将导致 subdir/index.json
成功 (200) 提供类型为 https://owner.github.io/repo/subdir/
的内容。但是 application/json
会提供 301 重定向,API 客户端可能无法容忍这种情况。
根据 https://jekyllrb.com/docs/configuration/options/ 的提示,我尝试创建 https://owner.github.io/repo/subdir
_config.yml
和include: .htaccess
.htaccess
没有成功。我还发现 https://github.com/jekyll/jekyll/issues/5454 暗示这是不可能的。