Skip to content

Commit

Permalink
cache and installation
Browse files Browse the repository at this point in the history
  • Loading branch information
ari-party committed Jun 3, 2024
1 parent dd5d156 commit 02d1534
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ $ curl -G https://example.com/svg \
-d 'transparent=1' \
```

the server sets the `cache-control` header to `max-age=3600, stale-while-revalidate=21600` so clients cache the response(s) for an hour and revalidate within 6.

## installation

### docker

```bash
# Pull the Docker image
$ docker pull ghcr.io/ari-party/umami-views:latest
Expand All @@ -35,3 +39,18 @@ $ docker run -d --name umami-views -p 8080:8080 ghcr.io/ari-party/umami-views:la
# `-p 8080:8080`, replace the lefthand 8080 with a port that you prefer,
# the server will be available on that port for you
```

### manual

```bash
# Clone the repository
$ git clone https://github.com/ari-party/umami-views.git

# Install the dependencies with pnpm (install with `npm i -g pnpm`)
$ pnpm install

# Copy the `.env.example` file as `.env` and edit the port to your wish

# Start the server
$ pnpm start
```
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ app.get('/svg', async (req, res) => {

res
.setHeader('content-type', 'image/svg+xml;charset=utf-8')
.setHeader('cache-control', 'max-age=60, must-revalidate')
.setHeader('cache-control', 'max-age=3600, stale-while-revalidate=21600')
.setHeader('date', String(new Date()))
.setHeader('expires', String(new Date(Date.now() + 60_000)))
.setHeader('expires', String(new Date(Date.now() + 3_600 * 1_000)))
.send(optimized);
} catch (error) {
console.warn(error);
Expand Down

0 comments on commit 02d1534

Please sign in to comment.