Demo assets server (#4055)

Adds an assets server to the demo worker, and reworks the existing asset
server to use the same code. There are a few simplifications to the code
due to some DX improvements working with R2 and caches. I also removed
the `HEAD` request from the assets server: i took a look at our logs and
it's not actually used at all.

This also fixes an issue where users could overwrite the contents of the
asset uploads bucket.

### Change type

- [x] `other`
This commit is contained in:
alex 2024-07-02 14:08:50 +01:00 committed by GitHub
parent adb84d97e3
commit dcfc6da604
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 240 additions and 209 deletions

View file

@ -30,6 +30,7 @@ const dotcom = path.relative(process.cwd(), path.resolve(__dirname, '../apps/dot
const env = makeEnv([
'APP_ORIGIN',
'ASSET_UPLOAD',
'ASSET_UPLOAD_SENTRY_DSN',
'ASSET_BUCKET_ORIGIN',
'CLOUDFLARE_ACCOUNT_ID',
'CLOUDFLARE_API_TOKEN',
@ -164,8 +165,9 @@ async function prepareDotcomApp() {
let didUpdateAssetUploadWorker = false
async function deployAssetUploadWorker({ dryRun }: { dryRun: boolean }) {
const workerId = `${previewId ?? env.TLDRAW_ENV}-tldraw-assets`
if (previewId && !didUpdateAssetUploadWorker) {
await setWranglerPreviewConfig(assetUpload, { name: `${previewId}-tldraw-assets` })
await setWranglerPreviewConfig(assetUpload, { name: workerId })
didUpdateAssetUploadWorker = true
}
@ -173,7 +175,15 @@ async function deployAssetUploadWorker({ dryRun }: { dryRun: boolean }) {
location: assetUpload,
dryRun,
env: env.TLDRAW_ENV,
vars: {},
vars: {
SENTRY_DSN: env.ASSET_UPLOAD_SENTRY_DSN,
TLDRAW_ENV: env.TLDRAW_ENV,
WORKER_NAME: workerId,
},
sentry: {
project: 'asset-upload-worker',
authToken: env.SENTRY_AUTH_TOKEN,
},
})
}