Skip to content

Commit

Permalink
Add PATH_PREFIX variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kotx committed Jun 5, 2022
1 parent 02fe7fb commit 3ed3cc5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import parseRange from "range-parser";

interface Env {
R2_BUCKET: R2Bucket,
CACHE_CONTROL?: string
CACHE_CONTROL?: string,
PATH_PREFIX?: string
}

type ParsedRange = { offset: number, length: number } | { suffix: number };
Expand Down Expand Up @@ -42,7 +43,7 @@ export default {

if (!response || !response.ok) {
console.warn("Cache miss");
const path = decodeURIComponent(url.pathname.substring(1));
const path = (env.PATH_PREFIX || "") + decodeURIComponent(url.pathname.substring(1));

let file: R2Object | R2ObjectBody | null | undefined;

Expand Down
4 changes: 3 additions & 1 deletion wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ workers_dev = true
[vars]
# The `cache-control` header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control. Optional, the `cache-control` header is omitted if unset.
CACHE_CONTROL = "max-age=86400"
# The string to prepend to each file path. Optional, nothing is prepended to the path if unset.
PATH_PREFIX = ""

[[r2_buckets]]
binding = "R2_BUCKET"
bucket_name = "kot" # Set this to your R2 bucket name. Required
preview_bucket_name = "kot" # Set this to your preview R2 bucket name. Can be equal to bucket_name. Optional
preview_bucket_name = "kot" # Set this to your preview R2 bucket name. Can be equal to bucket_name. Optional

0 comments on commit 3ed3cc5

Please sign in to comment.