Skip to content

Commit d9dac31

Browse files
andrelandgrafkentcdodds
authored andcommitted
update docs, add S3 URL to allowlist
1 parent 505685b commit d9dac31

File tree

3 files changed

+14
-29
lines changed

3 files changed

+14
-29
lines changed

app/routes/resources+/images.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ export async function loader({ request }: Route.LoaderArgs) {
88
headers.set('Cache-Control', 'public, max-age=31536000, immutable')
99
return getImgResponse(request, {
1010
headers,
11-
allowlistedOrigins: [domain],
12-
cacheFolder: process.env.NODE_ENV === 'production' ? '/data/images' : './data/images',
11+
allowlistedOrigins: [domain, process.env.AWS_ENDPOINT_URL_S3],
12+
cacheFolder:
13+
process.env.NODE_ENV === 'production' ? '/data/images' : './data/images',
1314
getImgSource: ({ params }) => {
1415
if (params.src.startsWith('/resources')) {
1516
// Fetch image from resource endpoint

docs/decisions/039-image-optimization.md renamed to docs/decisions/041-image-optimization.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ Introduce an image optimization endpoint using the
3434
[openimg package](https://github.com/andrelandgraf/openimg). We can then use the
3535
`Img` component to query for optimized images and iterate from there.
3636

37-
In the future, we may decide to look into [unpic-img](https://unpic.pics/img/)
38-
for futher enhancements on the client side and/or look into creating blurred
39-
placeholder images using openimg/node and openimg/vite or alternative solutions.
40-
4137
## Consequences
4238

4339
Serving newly added images will now lead to an image optimization step whenever
Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,19 @@
1-
# Images
2-
3-
The Epic Stack distinguishes between user images and static app image assets.
4-
User images are stored in SQLite along with the rest of the application data,
5-
while static images are stored in the [../public/img/](../public/img/) folder.
6-
See the [images decision doc](./decisions/018-images.md) for more details.
7-
8-
## User Images
9-
10-
User images (uploaded by a user) are stored in SQLite and served via resource
11-
routes, for example:
12-
[/resources/user-images/$imageId](../app/routes/resources+/user-images.$imageId.tsx).
13-
14-
## Image Optimization
1+
# Image Optimization
152

163
The Epic Stack uses [openimg](https://github.com/andrelandgraf/openimg) to
174
optimize images on demand, introduced via
185
[this decision doc](./decisions/039-image-optimization.md).
196

20-
### Server Part
7+
## Server Part
218

229
The [/resources/images](../app/routes/resources+/images.tsx) endpoint accepts
2310
the search parameters `src`, `w` (width), `h` (height), `format`, and `fit` to
2411
perform image transformations and serve optimized variants. The transformations
2512
are performed with `sharp`, and the optimized images are cached in
26-
`./data/images` on the filesystem and via HTTP caching.
13+
`./data/images` on the filesystem and via HTTP caching. All transformations happen
14+
via stream processing, so images are never loaded fully into memory at once.
2715

28-
### Client Part
16+
## Client Part
2917

3018
On the client side, the `Img` React component from openimg/react is used to
3119
query the [/resources/images](../app/routes/resources+/images.tsx) endpoint with
@@ -36,11 +24,11 @@ loading. It also computes `srcset` and `sizes` based on the provided `width` and
3624
`height` props. Use the `isAboveFold` prop on the `Img` component to priotize
3725
images that should load immediately.
3826

39-
### Image Sources
27+
## Image Sources
4028

4129
If you want to add a new image storage location, like an S3 bucket, update the
42-
[/resources/images](../app/routes/resources+/images.tsx) endpoint and modify the
43-
`getSource` function to instruct openimg on how to retrieve the source images
44-
from the new location. Currently, the endpoint uses fetch requests to retrieve
45-
user images from the resource route endpoints and the filesystem to retrieve
46-
static application assets from the public and assets folders.
30+
[/resources/images](../app/routes/resources+/images.tsx) endpoint and modify
31+
`getSource` and `allowlistedOrigins` to instruct openimg on how to retrieve the
32+
source images from the new location. Currently, the endpoint uses fetch requests
33+
to retrieve user images from the resource route endpoints and the filesystem to
34+
retrieve static application assets from the public and assets folders.

0 commit comments

Comments
 (0)