@@ -66,6 +66,7 @@ func esmRouter(db Database, esmStorage storage.Storage, logger *log.Logger) rex.
6666 startTime = time .Now ()
6767 globalETag = fmt .Sprintf (`W/"%s"` , VERSION )
6868 buildQueue = NewBuildQueue (int (config .BuildConcurrency ))
69+ npmrc = DefaultNpmRC ()
6970 )
7071
7172 return func (ctx * rex.Context ) any {
@@ -111,12 +112,7 @@ func esmRouter(db Database, esmStorage storage.Storage, logger *log.Logger) rex.
111112 h .Write ([]byte (options .SourceMap ))
112113 fmt .Fprintf (h , "%v" , options .Minify )
113114 hash := hex .EncodeToString (h .Sum (nil ))
114-
115- zoneId := ctx .R .Header .Get ("X-Zone-Id" )
116- if zoneId != "" && ! valid .IsDomain (zoneId ) {
117- zoneId = ""
118- }
119- savePath := normalizeSavePath (zoneId , fmt .Sprintf ("modules/transform/%s.mjs" , hash ))
115+ savePath := normalizeSavePath (fmt .Sprintf ("modules/transform/%s.mjs" , hash ))
120116
121117 // if previous build exists, return it directly
122118 if file , _ , err := esmStorage .Get (savePath ); err == nil {
@@ -413,11 +409,7 @@ func esmRouter(db Database, esmStorage storage.Storage, logger *log.Logger) rex.
413409 if len (hash ) != 40 || ! valid .IsHexString (hash ) {
414410 return rex .Status (404 , "Not Found" )
415411 }
416- zoneId := ctx .R .Header .Get ("X-Zone-Id" )
417- if zoneId != "" && ! valid .IsDomain (zoneId ) {
418- zoneId = ""
419- }
420- savePath := normalizeSavePath (zoneId , fmt .Sprintf ("modules/transform/%s.%s" , hash , ext ))
412+ savePath := normalizeSavePath (fmt .Sprintf ("modules/transform/%s.%s" , hash , ext ))
421413 f , fi , err := esmStorage .Get (savePath )
422414 if err != nil {
423415 return rex .Status (500 , err .Error ())
@@ -483,36 +475,6 @@ func esmRouter(db Database, esmStorage storage.Storage, logger *log.Logger) rex.
483475 return data
484476 }
485477
486- var npmrc * NpmRC
487- if v := ctx .R .Header .Get ("X-Npmrc" ); v != "" {
488- rc , err := NewNpmRcFromJSON ([]byte (v ))
489- if err != nil {
490- return rex .Status (400 , "Invalid Npmrc Header" )
491- }
492- npmrc = rc
493- } else {
494- npmrc = DefaultNpmRC ()
495- }
496-
497- zoneId := ctx .R .Header .Get ("X-Zone-Id" )
498- if zoneId != "" {
499- var scopeName string
500- if pkgName := toPackageName (pathname [1 :]); strings .HasPrefix (pkgName , "@" ) {
501- scopeName = pkgName [:strings .Index (pkgName , "/" )]
502- }
503- if scopeName != "" {
504- reg , ok := npmrc .ScopedRegistries [scopeName ]
505- if ! ok || (reg .Registry == jsrRegistry && reg .Token == "" && (reg .User == "" || reg .Password == "" )) {
506- zoneId = ""
507- }
508- } else if npmrc .Registry == npmRegistry && npmrc .Token == "" && (npmrc .User == "" || npmrc .Password == "" ) {
509- zoneId = ""
510- }
511- }
512- if zoneId != "" && valid .IsDomain (zoneId ) {
513- npmrc .zoneId = zoneId
514- }
515-
516478 if strings .HasPrefix (pathname , "/http://" ) || strings .HasPrefix (pathname , "/https://" ) {
517479 query := ctx .Query ()
518480 modUrl , err := url .Parse (pathname [1 :])
@@ -565,7 +527,7 @@ func esmRouter(db Database, esmStorage storage.Storage, logger *log.Logger) rex.
565527 h .Write ([]byte (ctxParam ))
566528 h .Write ([]byte (target ))
567529 h .Write ([]byte (v ))
568- savePath := normalizeSavePath (npmrc . zoneId , path .Join ("modules/x" , hex .EncodeToString (h .Sum (nil ))+ ".css" ))
530+ savePath := normalizeSavePath (path .Join ("modules/x" , hex .EncodeToString (h .Sum (nil ))+ ".css" ))
569531 r , fi , err := esmStorage .Get (savePath )
570532 if err != nil && err != storage .ErrNotFound {
571533 return rex .Status (500 , err .Error ())
@@ -715,7 +677,7 @@ func esmRouter(db Database, esmStorage storage.Storage, logger *log.Logger) rex.
715677 h .Write ([]byte (im ))
716678 h .Write ([]byte (target ))
717679 h .Write ([]byte (v ))
718- savePath := normalizeSavePath (npmrc . zoneId , path .Join ("modules/x" , hex .EncodeToString (h .Sum (nil ))+ ".mjs" ))
680+ savePath := normalizeSavePath (path .Join ("modules/x" , hex .EncodeToString (h .Sum (nil ))+ ".mjs" ))
719681 content , fi , err := esmStorage .Get (savePath )
720682 if err != nil && err != storage .ErrNotFound {
721683 return rex .Status (500 , err .Error ())
@@ -1237,7 +1199,7 @@ func esmRouter(db Database, esmStorage storage.Storage, logger *log.Logger) rex.
12371199 } else {
12381200 savePath = path .Join ("modules" , pathname )
12391201 }
1240- savePath = normalizeSavePath (npmrc . zoneId , savePath )
1202+ savePath = normalizeSavePath (savePath )
12411203 f , stat , err := esmStorage .Get (savePath )
12421204 if err != nil {
12431205 if err != storage .ErrNotFound {
@@ -1466,7 +1428,7 @@ func esmRouter(db Database, esmStorage storage.Storage, logger *log.Logger) rex.
14661428 if a := encodeBuildArgs (buildArgs , true ); a != "" {
14671429 args = "X-" + a
14681430 }
1469- savePath := normalizeSavePath (npmrc . zoneId , path .Join (fmt .Sprintf (
1431+ savePath := normalizeSavePath (path .Join (fmt .Sprintf (
14701432 "types/%s/%s" ,
14711433 esm .Name (),
14721434 args ,
@@ -1685,7 +1647,7 @@ func esmRouter(db Database, esmStorage storage.Storage, logger *log.Logger) rex.
16851647 // seem the build file is non-exist in the storage
16861648 // let's remove the build meta from the database and clear the cache
16871649 // then re-build the module
1688- key := npmrc . zoneId + ":" + build .Path ()
1650+ key := build .Path ()
16891651 db .Delete (key )
16901652 cacheLRU .Remove (key )
16911653 return rex .Status (500 , "Storage error, please try again" )
0 commit comments