providers/.docs/content/2.essentials/0.usage-on-x.md

51 lines
1.7 KiB
Markdown
Raw Normal View History

2023-12-26 22:35:58 +00:00
# How to use on X
2023-12-26 23:15:23 +00:00
The library can run in many environments, so it can be tricky to figure out how to set it up.
2023-12-31 03:35:48 +00:00
Here is a checklist. For more specific environments, keep reading below:
2023-12-26 23:15:23 +00:00
- When requests are very restricted (like browser client-side). Configure a proxied fetcher.
2023-12-31 03:35:48 +00:00
- When your requests come from the same device on which it will be streamed (not compatible with proxied fetcher). Set `consistentIpForRequests: true`.
2023-12-26 23:15:23 +00:00
- To set a target. Consult [Targets](./1.targets.md).
2023-12-31 03:35:48 +00:00
To make use of the examples below, check out the following pages:
2023-12-29 16:03:28 +00:00
- [Quick start](../1.get-started/1.quick-start.md)
2023-12-29 16:05:01 +00:00
- [Using streams](../2.essentials/4.using-streams.md)
2023-12-26 23:15:23 +00:00
## NodeJs server
```ts
import { makeProviders, makeStandardFetcher, targets } from '@movie-web/providers';
const providers = makeProviders({
fetcher: makeStandardFetcher(fetch),
target: chooseYourself, // check out https://providers.docs.movie-web.app/essentials/targets
})
```
## Browser client-side
Using the provider package client-side requires a hosted version of simple-proxy.
2023-12-26 23:15:23 +00:00
Read more [about proxy fetchers](./2.fetchers.md#using-fetchers-on-the-browser).
```ts
import { makeProviders, makeStandardFetcher, targets } from '@movie-web/providers';
const proxyUrl = "https://your.proxy.workers.dev/";
const providers = makeProviders({
fetcher: makeStandardFetcher(fetch),
proxiedFetcher: makeSimpleProxyFetcher(proxyUrl, fetch),
target: target.BROWSER,
})
```
## React native
```ts
import { makeProviders, makeStandardFetcher, targets } from '@movie-web/providers';
const providers = makeProviders({
fetcher: makeStandardFetcher(fetch),
target: target.NATIVE,
consistentIpForRequests: true,
})
```