Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
7 changes: 5 additions & 2 deletions modules/actions/serveFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(', ')
Expand Down
5 changes: 4 additions & 1 deletion modules/utils/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand Down Expand Up @@ -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`;
Expand Down