Skip to content

Commit

Permalink
refactor: set base url as env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
boywithkeyboard committed Apr 6, 2024
1 parent f5539e8 commit cb0d638
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:

- name: Run Test
env:
BASE_URL: ${{ secrets.TEST_BASE_URL }}
R2_HOSTNAME: ${{ secrets.TEST_R2_HOSTNAME }}
S3_ACCESS_KEY_ID: ${{ secrets.TEST_S3_ACCESS_KEY_ID }}
S3_BUCKET: ${{ secrets.TEST_S3_BUCKET }}
Expand Down
1 change: 1 addition & 0 deletions registry/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ declare global {
namespace NodeJS {
interface ProcessEnv {
R2_HOSTNAME: string
BASE_URL: string
S3_BUCKET: string
S3_ENDPOINT: string
S3_ACCESS_KEY_ID: string
Expand Down
10 changes: 5 additions & 5 deletions registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ app.setNotFoundHandler(async (req, res) => {

return await respondWith(res, 307, null, {
headers: {
Location: 'https://deno.re' + arr.join('/')
Location: process.env.BASE_URL + arr.join('/')
}
})
}
Expand Down Expand Up @@ -173,10 +173,10 @@ app.setNotFoundHandler(async (req, res) => {
content = Buffer.from(content, 'base64').toString('utf-8')
} else if (entryPoint.endsWith('ts')) {
contentType = filePathToContentType('.ts')
content = `export * from 'https://deno.re/${user}/${repo}@${tag}${entryPoint}'`
content = `export * from '${process.env.BASE_URL}/${user}/${repo}@${tag}${entryPoint}'`
} else {
contentType = filePathToContentType('.js')
content = `export * from 'https://deno.re/${user}/${repo}@${tag}${entryPoint}'`
content = `export * from '${process.env.BASE_URL}/${user}/${repo}@${tag}${entryPoint}'`
}
}

Expand All @@ -190,7 +190,7 @@ app.setNotFoundHandler(async (req, res) => {
'Cache-Control': 'public, max-age=2592000, immutable', // a month
'Content-Type': contentType + '; charset=utf-8',
'ETag': checksum,
...(typeHeader && { 'X-TypeScript-Types': 'https://deno.re/' + user + '/' + repo + '@' + tag + typeHeader })
...(typeHeader && { 'X-TypeScript-Types': process.env.BASE_URL + '/' + user + '/' + repo + '@' + tag + typeHeader })
},
resolve
})
Expand All @@ -202,7 +202,7 @@ app.setNotFoundHandler(async (req, res) => {
'Cache-Control': 'public, max-age=2592000, immutable', // a month
'Content-Type': contentType + '; charset=utf-8',
'ETag': checksum,
...(typeHeader && { 'X-TypeScript-Types': 'https://deno.re/' + user + '/' + repo + '@' + tag + typeHeader })
...(typeHeader && { 'X-TypeScript-Types': process.env.BASE_URL + '/' + user + '/' + repo + '@' + tag + typeHeader })
},
resolve
})
Expand Down

0 comments on commit cb0d638

Please sign in to comment.