Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
asadahimeka authored Feb 7, 2023
1 parent 369d8c8 commit 59d8674
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ booru was built for Node.js, and is only officially supported for Node.js. Issue

It's possible to use booru on the web using webpack (or similar), although your experience may vary. Some websites don't have the proper CORS headers, meaning that API requests to those sites from a browser will fail! This is not an issue I can fix in the package, and requires either that booru to add proper support themselves or for you to find a workaround for CORS.

For sites that do not support CORS, you can hack the code as follows, noting that this code should be placed before importing `@himeka/booru`.

The CORS proxy needs to support calls of the form `https://cors.example.com/https://konachan.net/post.json`.

```js
const _fetch = window.fetch
const proxy = 'https://cors.example.com/' // Replace with your own CORS proxy
window.fetch = (input, init) => {
let url = input.toString()
if (url.startsWith('https')) {
url = proxy + url
}
return _fetch(url, init)
}
```

## FAQ

### What are the properties of a `Post`?
Expand Down
16 changes: 16 additions & 0 deletions readme.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ booru 主要是为 Node.js 构建的,浏览器支持可能有限。
可以使用 webpack(或类似工具)在 web 上使用 booru,尽管体验可能会有所不同。
某些网站没有正确的 CORS 标头,这意味着从浏览器对这些网站的 API 请求将失败,需要自行解决跨域问题。

对于不支持 CORS 的站点,可以按如下代码 hack 一下,注意这段代码要放到引用 `@himeka/booru` 之前。

CORS 代理需要支持 `https://cors.example.com/https://konachan.net/post.json` 形式的调用。

```js
const _fetch = window.fetch
const proxy = 'https://cors.example.com/' // 替换成你自己的 CORS 代理
window.fetch = (input, init) => {
let url = input.toString()
if (url.startsWith('https')) {
url = proxy + url
}
return _fetch(url, init)
}
```

## FAQ

### `Post` 有什么属性?
Expand Down

0 comments on commit 59d8674

Please sign in to comment.