diff --git a/README.md b/README.md index 7699c87a..193a4807 100644 --- a/README.md +++ b/README.md @@ -37,17 +37,19 @@ 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` | +| 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` | +| `CACHE_CONTROL` | optional - overrides response header | `public,max-age=31536000` | ## Build Options @@ -61,6 +63,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 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(', ') 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`;