8
8
worker_connections 1024 ;
9
9
}
10
10
11
-
12
11
http {
13
12
# We literally only care about 2 types of files/payloads.
14
13
types {
@@ -27,15 +26,11 @@ http {
27
26
access_log logs/access.log upstreamlog;
28
27
29
28
lua_shared_dict npmConfig 32k ;
29
+ lua_shared_dict npmMeta 128M ;
30
+
30
31
init_by_lua_block {
31
- local npmConfig = ngx.shared.npmConfig
32
- local registry = os.getenv("npm_config_registry" ):gsub("/+$" , "" )
33
- local pattern = registry:gsub("%." , "%%." ):gsub("%-" , "%%-" )
34
- -- escape . and - which have special meaning in Lua patterns
35
- npmConfig:set ('npm_config_registry' , registry)
36
- npmConfig:set('npm_upstream_pattern' , pattern)
37
- -- ngx.log(ngx.ERR, 'using upstream base: ' , registry)
38
- -- ngx.log(ngx.ERR, 'using upstream pattern: ' , pattern)
32
+ local ephemeralNPM = require "ephemeral-npm"
33
+ ephemeralNPM.init()
39
34
}
40
35
41
36
server {
@@ -49,6 +44,14 @@ http {
49
44
try_files $uri @fetch-tgz;
50
45
}
51
46
location / {
47
+ content_by_lua_block {
48
+ local ephemeralNPM = require "ephemeral-npm"
49
+ ephemeralNPM.getPackage()
50
+ }
51
+ }
52
+ location /-@- {
53
+ internal ;
54
+ rewrite /-@-/(.+) /$1 break;
52
55
resolver 127.0.0.1 ipv6=off;
53
56
proxy_pass $npm_config_registry ;
54
57
proxy_buffers 32 1m ;
@@ -65,20 +68,17 @@ http {
65
68
header_filter_by_lua_block {
66
69
ngx.header.content_length = nil
67
70
}
68
- # replace all occurances of, eg. https://registry.npmjs.org with http://127.0.0.1:4873
69
71
body_filter_by_lua_block {
70
- local npmConfig = ngx.shared.npmConfig
71
- local upstream = npmConfig:get('npm_upstream_pattern' )
72
- -- need to construct URL because we may be proxying http<->https
73
- local base = ngx.var.scheme .. '://' .. ngx.var.http_host
74
- -- ngx.log(ngx.ERR, "Modifying JSON of " .. ngx.var.uri .. " to replace '" .. upstream .. "' with '" .. base .. "' ")
75
- ngx.arg[1] = string.gsub(ngx.arg[1], upstream, base)
72
+ local ephemeralNPM = require "ephemeral-npm"
73
+ ephemeralNPM.filterPackageBody()
76
74
}
77
75
}
78
76
location @fetch-tgz {
79
77
internal ;
80
78
resolver 127.0.0.1 ipv6=off;
81
79
proxy_pass $npm_config_registry ;
80
+ proxy_buffering on ;
81
+ proxy_buffers 512 512k ;
82
82
proxy_store on ;
83
83
proxy_store_access user:rw group:rw all:r;
84
84
proxy_temp_path /tmp/npm/temp;
0 commit comments