Skip to content

Commit

Permalink
/proxy endpoint and some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
armandabric committed Aug 17, 2020
1 parent 80b055d commit 7b4dc98
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
# fake-sanity-image-cdn

## What is it?

A proxy to use Sanity <code>@sanity/image-url</code> helper with
fake image. Usefull in tests or storybook.

## How to use it?

Use this proxy service as the `baseUrl` when you create the
imageUrlBuilder instanse:

```js
import imageUrlBuilder from '@sanity/image-url';

const myConfiguredSanityClient = {
/_ ... _/,
baseUrl: "https://fake-sanity-image-cdn.vercel.app/proxy/"
};

const builder = imageUrlBuilder(myConfiguredSanityClient);

console.log(builder.image("...").url())</code></pre>
```

## Limitations

- Do not support `webp` image transformations (`jpg` image will alwails be returned)
1 change: 0 additions & 1 deletion api/proxy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const EXTRACT_INFO_FROM_PATH_REGEX = /([a-zA-Z0-9]+)-([0-9]+)x([0-9]+)\.([a-z]+)$/i;

// TODO: Rename endpoint to `/api/sanity-endpoint`
// TODO: Extract width and height from the query to overload the one in the path
// TODO: Extract the format from the query to validate it (picsum.photos only support jpg)
export default (req, res) => {
Expand Down
9 changes: 8 additions & 1 deletion vercel.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{
"rewrites": [{ "source": "/bar(/.*)", "destination": "/api/proxy?path=$1" }]
"redirects": [
{
"source": "/",
"statusCode": 301,
"destination": "https://github.com/gogaille/fake-sanity-image-cdn"
}
],
"rewrites": [{ "source": "/proxy(/.*)", "destination": "/api/proxy?path=$1" }]
}

0 comments on commit 7b4dc98

Please sign in to comment.