mirror of
https://github.com/harish2704/npm-offline-registry.git
synced 2026-09-10 06:21:09 +00:00
Add ENABLE_NPM_FAILOVER option, set to true by default, with false disabling upstream failover.
This commit is contained in:
@@ -40,3 +40,9 @@ I believe all the above said tools will be available in a typical UNIX machine.
|
|||||||
# Configurations
|
# Configurations
|
||||||
|
|
||||||
Please check config.js. All config values can be over-written by `environment-variables`
|
Please check config.js. All config values can be over-written by `environment-variables`
|
||||||
|
|
||||||
|
# Using npm-offline-registry as a completely isolated registry
|
||||||
|
|
||||||
|
If you set the ``ENABLE_NPM_FAILOVER`` config value to ``false`` then npm-offlin-registry will not attempt to
|
||||||
|
contact the upstream NPM registry for unknown packages and instead return a 404 response, meaning you can use
|
||||||
|
it as an alternative to the NPM registry behind a firewall / isolated from the internet.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ var utils = require( __dirname + '/./utils');
|
|||||||
|
|
||||||
var NPM_PATH = config.NPM_PATH;
|
var NPM_PATH = config.NPM_PATH;
|
||||||
var REGISTRY_NAME = config.REGISTRY_NAME;
|
var REGISTRY_NAME = config.REGISTRY_NAME;
|
||||||
|
var ENABLE_NPM_FAILOVER = config.ENABLE_NPM_FAILOVER;
|
||||||
|
|
||||||
|
|
||||||
var fetchAndCacheMetadata = utils.fetchAndCacheMetadata;
|
var fetchAndCacheMetadata = utils.fetchAndCacheMetadata;
|
||||||
@@ -36,8 +37,12 @@ app.get( '/:package', function( req, res, next ){
|
|||||||
return fileExists( cacheFile )
|
return fileExists( cacheFile )
|
||||||
.tap( function( isExists ){
|
.tap( function( isExists ){
|
||||||
if( !isExists ){
|
if( !isExists ){
|
||||||
res._log.cacheHit = '---';
|
if ( ENABLE_NPM_FAILOVER ) {
|
||||||
return fetchAndCacheMetadata( packageName, cacheFile );
|
res._log.cacheHit = '---';
|
||||||
|
return fetchAndCacheMetadata( packageName, cacheFile );
|
||||||
|
} else {
|
||||||
|
return res.status( 404 ).json( {} );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then( function( ){
|
.then( function( ){
|
||||||
@@ -60,8 +65,12 @@ app.get( '/:package/-/:tarball', function( req, res, next ){
|
|||||||
fileExists( packagePath )
|
fileExists( packagePath )
|
||||||
.tap( function( isExists ){
|
.tap( function( isExists ){
|
||||||
if( !isExists ){
|
if( !isExists ){
|
||||||
res._log.cacheHit = '---';
|
if ( ENABLE_NPM_FAILOVER ) {
|
||||||
return fetchAndCacheTarball( packageName, version, packagePath );
|
res._log.cacheHit = '---';
|
||||||
|
return fetchAndCacheTarball( packageName, version, packagePath );
|
||||||
|
} else {
|
||||||
|
return res.status( 404 ).json( {} );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then( function(){
|
.then( function(){
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
var defaultConfig = {
|
var defaultConfig = {
|
||||||
NPM_PATH : process.env.HOME + '/.npm',
|
NPM_PATH : process.env.HOME + '/.npm',
|
||||||
REGISTRY_NAME : 'registry.npmjs.org',
|
REGISTRY_NAME : 'registry.npmjs.org',
|
||||||
PORT: 8234
|
PORT: 8234,
|
||||||
|
ENABLE_NPM_FAILOVER: true
|
||||||
};
|
};
|
||||||
|
|
||||||
var config = {};
|
var config = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user