Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

安装内网发布的包,报错,外网的包可以正常同步 #1573

Closed
tolerance-go opened this issue Jun 3, 2020 · 3 comments
Closed

Comments

@tolerance-go
Copy link

tolerance-go commented Jun 3, 2020

image

docs/dockerfile/config.js 配置如下

'use strict';

var mkdirp = require('mkdirp');
var copy = require('copy-to');
var path = require('path');
var fs = require('fs');
var os = require('os');

var version = require('../package.json').version;

var root = path.dirname(__dirname);
var dataDir = process.env.CNPM_DATA_DIR ;

var config = {
  version: version,
  dataDir: dataDir,

  /**
   * Cluster mode
   */
  enableCluster: true,
  numCPUs: os.cpus().length,

  /*
   * server configure
   */

  registryPort: 7001,
  webPort: 7002,
  bindingHost: '0.0.0.0', // binding on 0.0.0.0 for outside of container access

  // debug mode
  // if in debug mode, some middleware like limit wont load
  // logger module will print to stdout
  debug: process.env.NODE_ENV === 'development',
  // page mode, enable on development env
  pagemock: process.env.NODE_ENV === 'development',
  // session secret
  sessionSecret: 'cnpmjs.org test session secret',
  // max request json body size
  jsonLimit: '10mb',
  // log dir name
  logdir: path.join(dataDir, 'logs'),
  // update file template dir
  uploadDir: path.join(dataDir, 'downloads'),
  // web page viewCache
  viewCache: false,

  // config for koa-limit middleware
  // for limit download rates
  limit: {
    enable: false,
    token: 'koa-limit:download',
    limit: 1000,
    interval: 1000 * 60 * 60 * 24,
    whiteList: [],
    blackList: [],
    message: 'request frequency limited, any question, please contact fengmk2@gmail.com',
  },

  enableCompress: false, // enable gzip response or not

  // default system admins
  admins: {
    // name: email
    yangbin: 'yangbin@tongyu.tech',
  },

  // email notification for errors
  // check https://github.com/andris9/Nodemailer for more informations
  mail: {
    enable: false,
    appname: 'cnpmjs.org',
    from: 'cnpmjs.org mail sender <adderss@gmail.com>',
    service: 'gmail',
    auth: {
      user: 'address@gmail.com',
      pass: 'your password'
    }
  },

  logoURL: 'https://os.alipayobjects.com/rmsportal/oygxuIUkkrRccUz.jpg', // cnpm logo image url
  adBanner: '',
  customReadmeFile: '', // you can use your custom readme file instead the cnpm one
  customFooter: '', // you can add copyright and site total script html here
  npmClientName: 'tnpm', // use `${name} install package`
  packagePageContributorSearch: true, // package page contributor link to search, default is true

  // max handle number of package.json `dependencies` property
  maxDependencies: 200,
  // backup filepath prefix
  backupFilePrefix: '/cnpm/backup/',

  /**
   * database config
   */

  database: {
    db: 'cnpmjs_test',
    username: 'root',

    // the sql dialect of the database
    // - currently supported: 'mysql', 'sqlite', 'postgres', 'mariadb'
    dialect: 'mysql',

    // the Docker container network hostname defined at docker-compose.yml
    host: 'mysql-db',

    // custom port; default: 3306
    port: 3306,

    // use pooling in order to reduce db connection overload and to increase speed
    // currently only for mysql and postgresql (since v1.5.0)
    pool: {
      maxConnections: 10,
      minConnections: 0,
      maxIdleTime: 30000
    },

    // the storage engine for 'sqlite'
    // default store into ~/.cnpmjs.org/data.sqlite
    //storage: path.join(dataDir, 'data.sqlite'),

    logging: !!process.env.SQL_DEBUG,
  },

  // package tarball store in local filesystem by default
  nfs: require('fs-cnpm')({
    dir: path.join(dataDir, 'nfs')
  }),
  // if set true, will 302 redirect to `nfs.url(dist.key)`
  downloadRedirectToNFS: false,

  // registry url name
  registryHost: 'npm.tongyu.tech:7001',

  /**
   * registry mode config
   */

  // enable private mode or not
  // private mode: only admins can publish, other users just can sync package from source npm
  // public mode: all users can publish
  enablePrivate: false,
  forcePublishWithScope: true,

  // registry scopes, if don't set, means do not support scopes
  scopes: [ '@ty', '@ty-experiment' ],

  // some registry already have some private packages in global scope
  // but we want to treat them as scoped private packages,
  // so you can use this white list.
  privatePackages: [],

  /**
   * sync configs
   */

  // the official npm registry
  // cnpm wont directly sync from this one
  // but sometimes will request it for some package infomations
  // please don't change it if not necessary
  officialNpmRegistry: 'https://registry.npmjs.com',
  officialNpmReplicate: 'https://replicate.npmjs.com',

  // sync source, upstream registry
  // If you want to directly sync from official npm's registry
  // please drop them an email first
  sourceNpmRegistry: 'https://registry.npm.taobao.org',

  // upstream registry is base on cnpm/cnpmjs.org or not
  // if your upstream is official npm registry, please turn it off
  sourceNpmRegistryIsCNpm: true,

  // if install return 404, try to sync from source registry
  syncByInstall: true,

  // sync mode select
  // none: do not sync any module, proxy all public modules from sourceNpmRegistry
  // exist: only sync exist modules
  // all: sync all modules
  syncModel: 'exist', // 'none', 'all', 'exist'

  syncConcurrency: 1,
  // sync interval, default is 10 minutes
  syncInterval: '10m',

  // sync polular modules, default to false
  // because cnpm can't auto sync tag change for now
  // so we want to sync popular modules to ensure their tags
  syncPopular: false,
  syncPopularInterval: '1h',
  // top 100
  topPopular: 100,

  // sync devDependencies or not, default is false
  syncDevDependencies: false,

  // changes streaming sync
  syncChangesStream: false,
  handleSyncRegistry: 'http://npm.tongyu.tech:7001',

  // badge subject on http://shields.io/
  badgePrefixURL: 'https://img.shields.io/badge',
  badgeSubject: 'cnpm',

  // custom user service, @see https://github.com/cnpm/cnpmjs.org/wiki/Use-Your-Own-User-Authorization
  // when you not intend to ingegrate with your company's user system, then use null, it would
  // use the default cnpm user system
  userService: null,

  // always-auth https://docs.npmjs.com/misc/config#always-auth
  // Force npm to always require authentication when accessing the registry, even for GET requests.
  alwaysAuth: false,

  // if you're behind firewall, need to request through http proxy, please set this
  // e.g.: `httpProxy: 'http://proxy.mycompany.com:8080'`
  httpProxy: null,

  // snyk.io root url
  snykUrl: 'https://snyk.io',

  // https://github.com/cnpm/cnpmjs.org/issues/1149
  // if enable this option, must create module_abbreviated and package_readme table in database
  enableAbbreviatedMetadata: true,

  // global hook function: function* (envelope) {}
  // envelope format please see https://github.com/npm/registry/blob/master/docs/hooks/hooks-payload.md#payload
  globalHook: null,
};

if (process.env.NODE_ENV !== 'test') {
  var customConfig;
  if (process.env.NODE_ENV === 'development') {
    customConfig = path.join(root, 'config', 'config.js');
  } else {
    // 1. try to load `$dataDir/config.json` first, not exists then goto 2.
    // 2. load config/config.js, everything in config.js will cover the same key in index.js
    customConfig = path.join(dataDir, 'config.json');
    if (!fs.existsSync(customConfig)) {
      customConfig = path.join(root, 'config', 'config.js');
    }
  }
  if (fs.existsSync(customConfig)) {
    copy(require(customConfig)).override(config);
  }
}

mkdirp.sync(config.logdir);
mkdirp.sync(config.uploadDir);

module.exports = config;

config.loadConfig = function (customConfig) {
  if (!customConfig) {
    return;
  }
  copy(customConfig).override(config);
};
@tolerance-go
Copy link
Author

tolerance-go commented Jun 3, 2020

其实不知道具体作用,我修改了以下配置没有生效,安装内网的包会请求 127.0.0.1:7001
registryHost: 'npm.tongyu.tech:7001',
handleSyncRegistry: 'http://npm.tongyu.tech:7001',

~/.zshrc

#alias for tnpm
alias tnpm="npm --registry=http://npm.tongyu.tech:7001 \
  --cache=$HOME/.npm/.cache/tnpm \
  --disturl=https://npm.taobao.org/mirrors/node \
  --userconfig=$HOME/.tnpmrc"

@tolerance-go
Copy link
Author

tolerance-go commented Jun 3, 2020

我发现是本地请求库的问题,如果我请求是 scopes 下的包,会指向 127.0.0.1,这是服务端返回嘛?我需要设置本地代理嘛?

image

如果使用 yarn,则正常,现在推测是我本地的问题,但是没啥思路,求助求助

image

@chwech
Copy link

chwech commented Dec 7, 2020

same issue. 使用yarn能下载scopes包,使用npm不行。配置修改了registryHost为自己服务器ip端口。

$ yarn add @degon/vue-cli-plugin-admin-template
yarn add v1.22.10
info No lockfile found.
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 1 new dependency.
info Direct dependencies
└─ @degon/vue-cli-plugin-admin-template@0.0.1
info All dependencies
└─ @degon/vue-cli-plugin-admin-template@0.0.1
Done in 1.26s.

$ npm i @degon/vue-cli-plugin-admin-template
npm ERR! code ECONNREFUSED
npm ERR! errno ECONNREFUSED
npm ERR! FetchError: request to http://127.0.0.1:7001/@degon/vue-cli-plugin-admin-template/download/@degon/vue-cli-plugin-admin-template-0.0.1.tgz failed, reason: connect ECONNREFUSED 127.0.0.1:7001
npm ERR!     at ClientRequest.<anonymous> (D:\nvm\nvm\v12.16.1\node_modules\npm\node_modules\node-fetch-npm\src\index.js:68:14)
npm ERR!     at ClientRequest.emit (events.js:311:20)
npm ERR!     at Socket.socketErrorListener (_http_client.js:426:9)
npm ERR!     at Socket.emit (events.js:311:20)
npm ERR!     at emitErrorNT (internal/streams/destroy.js:92:8)
npm ERR!     at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
npm ERR!     at processTicksAndRejections (internal/process/task_queues.js:84:21)
npm ERR!  FetchError: request to http://127.0.0.1:7001/@degon/vue-cli-plugin-admin-template/download/@degon/vue-cli-plugin-admin-template-0.0.1.tgz failed, reason: connect ECONNREFUSED 127.0.0.1:7001
npm ERR!     at ClientRequest.<anonymous> (D:\nvm\nvm\v12.16.1\node_modules\npm\node_modules\node-fetch-npm\src\index.js:68:14)
npm ERR!     at ClientRequest.emit (events.js:311:20)
npm ERR!     at Socket.socketErrorListener (_http_client.js:426:9)
npm ERR!     at Socket.emit (events.js:311:20)
npm ERR!     at emitErrorNT (internal/streams/destroy.js:92:8)
npm ERR!     at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
npm ERR!     at processTicksAndRejections (internal/process/task_queues.js:84:21) {
npm ERR!   message: 'request to http://127.0.0.1:7001/@degon/vue-cli-plugin-admin-template/download/@degon/vue-cli-plugin-admin-template-0.0.1.tgz failed, reason: connect ECONNREFUSED 127.0.0.1:7001',
npm ERR!   type: 'system',
npm ERR!   errno: 'ECONNREFUSED',
npm ERR!   code: 'ECONNREFUSED',
npm ERR!   stack: 'FetchError: request to http://127.0.0.1:7001/@degon/vue-cli-plugin-admin-template/download/@degon/vue-cli-plugin-admin-template-0.0.1.tgz failed, reason: connect ECONNREFUSED 127.0.0.1:7001\n' +
npm ERR!     '    at ClientRequest.<anonymous> (D:\\nvm\\nvm\\v12.16.1\\node_modules\\npm\\node_modules\\node-fetch-npm\\src\\index.js:68:14)\n' +
npm ERR!     '    at ClientRequest.emit (events.js:311:20)\n' +
npm ERR!     '    at Socket.socketErrorListener (_http_client.js:426:9)\n' +
npm ERR!     '    at Socket.emit (events.js:311:20)\n' +
npm ERR!     '    at emitErrorNT (internal/streams/destroy.js:92:8)\n' +
npm ERR!     '    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)\n' +
npm ERR!     '    at processTicksAndRejections (internal/process/task_queues.js:84:21)'
npm ERR! }
npm ERR!
npm ERR! If you are behind a proxy, please make sure that the
npm ERR! 'proxy' config is set properly.  See: 'npm help config'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2020-12-07T02_53_13_971Z-debug.log

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants