npm-cache-proxy/readme.md
2019-04-22 12:49:32 +03:00

2.6 KiB

npm-cache-proxy

Docker Cloud Build Status

Download

You can download binary for your platform on the Releases page. Alternatively, you can use Docker Image.

Usage

ncp

Start proxy server.

Options Env Default Description
--listen <address> LISTEN_ADDRESS locahost:8080 Address to listen
--upstream <address> UPSTREAM_ADDRESS https://registry.npmjs.org Upstream registry address
--cache-limit <count> CACHE_LIMIT - Cached packages count limit
--cache-ttl <timeout> CACHE_TTL 3600 Cache expiration timeout in seconds
--redis-address <address> REDIS_ADDRESS http://localhost:6379 Redis address
--redis-database <database> REDIS_DATABASE 0 Redis database
--redis-password <password> REDIS_PASSWORD - Redis password
--redis-prefix <prefix> REDIS_PREFIX ncp- Redis keys prefix

ncp list

List cached packages.

ncp purge

Purge cached packages.

Programmatic usage

package main

import (
	"net/http"
	"time"

	npmproxy "github.com/emeralt/npm-cache-proxy/proxy"
	"github.com/go-redis/redis"
)

func main() {
	proxy := npmproxy.Proxy{
		Database: npmproxy.DatabaseRedis{
			Client: redis.NewClient(&redis.Options{
				Addr:     "localhost:6379",
			}),
		},
		HttpClient: &http.Client{},
		GetOptions: func() (npmproxy.Options, error) {
			return npmproxy.Options{
				DatabasePrefix:     "ncp-",
				DatabaseExpiration: 1 * time.Hour,
				UpstreamAddress:    "https://registry.npmjs.org",
			}, nil
		},
	}

	proxy.Server(npmproxy.ServerOptions{
		ListenAddress: "localhost:8080",
	}).ListenAndServe()
}

License

MIT