From ad330ab902dd81f54bdc116c0944cbc88b0849c9 Mon Sep 17 00:00:00 2001 From: Igor Pomelnikov Date: Thu, 1 Aug 2024 11:44:22 +0300 Subject: [PATCH 1/4] Enable work with GitLab registry by adding --GITLAB_REGISTRY. --- modules/utils/npm.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/utils/npm.js b/modules/utils/npm.js index ba378516..e25e3e65 100644 --- a/modules/utils/npm.js +++ b/modules/utils/npm.js @@ -8,6 +8,9 @@ import bufferStream from './bufferStream.js'; const npmRegistryURL = process.env.NPM_REGISTRY_URL || 'https://registry.npmjs.org'; +const gitlabRegistry = + process.env.GITLAB_REGISTRY; + const agent = new https.Agent({ keepAlive: true }); @@ -167,7 +170,7 @@ export async function getPackageConfig(packageName, version, log) { * Returns a stream of the tarball'd contents of the given package. */ export async function getPackage(packageName, version, log) { - const tarballName = isScopedPackageName(packageName) + const tarballName = isScopedPackageName(packageName) && !gitlabRegistry ? packageName.split('/')[1] : packageName; const tarballURL = `${npmRegistryURL}/${packageName}/-/${tarballName}-${version}.tgz`; From 93f6706bc386e8b5c6e95a8003f17dd9783795dc Mon Sep 17 00:00:00 2001 From: Igor Pomelnikov <88272503+IgorPomelnikov@users.noreply.github.com> Date: Thu, 1 Aug 2024 11:50:18 +0300 Subject: [PATCH 2/4] Update README.md Add descr of GITLAB_REGISTRY key. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7699c87a..e4aa7821 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ These values can be set on the system environment when starting the unpkg `serve | `ORIGIN` | optional | `https://unpkg.com` | | `CLOUDFLARE_EMAIL` | optional | `null` | | `CLOUDFLARE_KEY` | optional | `null` | +| `GITLAB_REGISTRY` | optional - enable work with GitLab npm registry | `null` | ## Build Options @@ -61,6 +62,7 @@ Use a `.env` file to set the following options when building the app with `npm r ## Documentation Please visit [the UNPKG website](https://unpkg.com) to learn more about how to use it. +Visit [GitLab docs](https://docs.gitlab.com/ee/api/packages/npm.html) to learn more about npm rigestry in GitLab. ## Sponsors From 02ca547054cb330b1c8fbe91be95f06031ea9e9d Mon Sep 17 00:00:00 2001 From: Igor Pomelnikov <88272503+IgorPomelnikov@users.noreply.github.com> Date: Thu, 1 Aug 2024 12:18:23 +0300 Subject: [PATCH 3/4] Update README.md --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e4aa7821..4cd5715a 100644 --- a/README.md +++ b/README.md @@ -37,18 +37,18 @@ node node_modules/unpkg-server/server.js \ These values can be set on the system environment when starting the unpkg `server.js`. -| Flag | Options / Description | Default value | -| ---------------------- | ------------------------------------------------ | ---------------------------- | -| `NPM_REGISTRY_URL` | optional - private registry url | `https://registry.npmjs.org` | -| `PORT` | optional - port to listen on | `8080` | -| `GOOGLE_CLOUD_PROJECT` | The GCP project ID. | `null` | -| `GAE_ENV` | `standard` to enable `@google-cloud/trace-agent` | `null` | -| `DEBUG` | enableDebugging | `false` | -| `ENABLE_CLOUDFLARE` | optional `true` or `false` | `false` | -| `ORIGIN` | optional | `https://unpkg.com` | -| `CLOUDFLARE_EMAIL` | optional | `null` | -| `CLOUDFLARE_KEY` | optional | `null` | -| `GITLAB_REGISTRY` | optional - enable work with GitLab npm registry | `null` | +| Flag | Options / Description | Default value | +| ---------------------- | ------------------------------------------------------ | ---------------------------- | +| `NPM_REGISTRY_URL` | optional - private registry url | `https://registry.npmjs.org` | +| `PORT` | optional - port to listen on | `8080` | +| `GOOGLE_CLOUD_PROJECT` | The GCP project ID. | `null` | +| `GAE_ENV` | `standard` to enable `@google-cloud/trace-agent` | `null` | +| `DEBUG` | enableDebugging | `false` | +| `ENABLE_CLOUDFLARE` | optional `true` or `false` | `false` | +| `ORIGIN` | optional | `https://unpkg.com` | +| `CLOUDFLARE_EMAIL` | optional | `null` | +| `CLOUDFLARE_KEY` | optional | `null` | +| `GITLAB_REGISTRY` | optional - enable work with GitLab npm scoped packages | `null` | ## Build Options From e1fc918d9fdd9900346a9caa4539f94bd89e3932 Mon Sep 17 00:00:00 2001 From: Igor Pomelnikov Date: Mon, 5 Aug 2024 13:41:50 +0300 Subject: [PATCH 4/4] Add the ability to override the cache-control header. --- README.md | 1 + modules/actions/serveFile.js | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4cd5715a..193a4807 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ These values can be set on the system environment when starting the unpkg `serve | `CLOUDFLARE_EMAIL` | optional | `null` | | `CLOUDFLARE_KEY` | optional | `null` | | `GITLAB_REGISTRY` | optional - enable work with GitLab npm scoped packages | `null` | +| `CACHE_CONTROL` | optional - overrides response header | `public,max-age=31536000` | ## Build Options diff --git a/modules/actions/serveFile.js b/modules/actions/serveFile.js index 7551b00b..85260966 100644 --- a/modules/actions/serveFile.js +++ b/modules/actions/serveFile.js @@ -10,12 +10,15 @@ export default function serveFile(req, res) { if (ext) { tags.push(`${ext}-file`); } - + const cacheControl = + process.env.CACHE_CONTROL; res .set({ 'Content-Type': getContentTypeHeader(req.entry.contentType), 'Content-Length': req.entry.size, - 'Cache-Control': 'public, max-age=31536000', // 1 year + 'Cache-Control': cacheControl + ? cacheControl + : 'public, max-age=31536000', // 1 year 'Last-Modified': req.entry.lastModified, ETag: etag(req.entry.content), 'Cache-Tag': tags.join(', ')