Skip to content

Commit

Permalink
Make imgproxy setup optional for local dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed Jul 30, 2023
1 parent 0e41690 commit f243319
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ You should then be able to access the site at `localhost:3000` and any changes y

To enable Web Push locally, you will need to set the `VAPID_*` env vars. `VAPID_MAILTO` needs to be a email address using the `mailto:` scheme. For `NEXT_PUBLIC_VAPID_KEY` and `VAPID_PRIVKEY`, you can run `npx web-push generate-vapid-keys`.

# imgproxy

To configure the image proxy, you will need to set the `IMGPROXY_` env vars. `NEXT_PUBLIC_IMGPROXY_URL` needs to point to the image proxy service. `IMGPROXY_KEY` and `IMGPROXY_SALT` can be set using `openssl rand -hex 64`.

# stack
The site is written in javascript using Next.js, a React framework. The backend API is provided via graphql. The database is postgresql modelled with prisma. The job queue is also maintained in postgresql. We use lnd for our lightning node. A customized Bootstrap theme is used for styling.

Expand Down
9 changes: 9 additions & 0 deletions api/resolvers/imgproxy/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { createHmac } from 'node:crypto'
import { extractUrls } from '../../../lib/md'

const imgProxyEnabled = process.env.NODE_ENV === 'production' ||
(process.env.NEXT_PUBLIC_IMGPROXY_URL && process.env.IMGPROXY_SALT && process.env.IMGPROXY_KEY)

if (!imgProxyEnabled) {
console.warn('IMGPROXY_* env vars not set, imgproxy calls are no-ops now')
}

const IMGPROXY_URL = process.env.NEXT_PUBLIC_IMGPROXY_URL
const IMGPROXY_SALT = process.env.IMGPROXY_SALT
const IMGPROXY_KEY = process.env.IMGPROXY_KEY
Expand Down Expand Up @@ -36,6 +43,8 @@ const isImageURL = async url => {
}

export const proxyImages = async text => {
if (!imgProxyEnabled) return text

const urls = extractUrls(text)
for (const url of urls) {
if (url.startsWith(IMGPROXY_URL)) continue
Expand Down

0 comments on commit f243319

Please sign in to comment.