当前位置:网站首页>Every minute teaches you to build enterprise class NPM private warehouse

Every minute teaches you to build enterprise class NPM private warehouse

2021-04-02 15:16:52 InfoQ

{"type":"doc","content":[{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":" Preface "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"npm As a package management tool , Whether you are a pan front end or a large front end, you can't do without it . It's convenient for thousands of teenagers . Let's step over Ctrl+C、Ctrl+V, adopt  "},{"type":"codeinline","content":[{"type":"text","text":"npm install x"}]},{"type":"text","text":"  To introduce other people's excellent code modules into your own projects . The reason why these excellent modules can be shared , On the one hand, there are npm Such a package management tool , The other is npm Warehouse ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" about npm Warehouse , If you're still using npm perhaps cnpm In the case of such official sources . So you need to think about how to build a private npm Warehouse . Next, we will explain the enterprise level from three aspects npm Private warehouse building things , Teach you in minutes ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Why do you need to build a private company npm Warehouse "}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" How to build a private warehouse "}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Build a private warehouse "}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":" Why do you need to build a private company npm Warehouse "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" As usual , Let's talk about why we need to build a private warehouse . There are a lot of mature npm The source can be used , such as :"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"npm : https:\/\/registry.npmjs.org\/"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"cnpm : http:\/\/r.cnpmjs.org\/"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"taobao: https:\/\/registry.npm.taobao.org\/"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"nj:https:\/\/registry.nodejitsu.com\/"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"npmMirror  https:\/\/skimdb.npmjs.com\/registry\/"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"…."}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" With so many public warehouses already in place , Is it necessary to set up a private system Warehouse ? repeat \" To build the wheels \"? Or self hi ? If we consider from the following aspects , Maybe it can get rid of the doubt in my heart ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"1. stability "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" The first is network access stability , The private warehouse is maintained by our own company , What problems can be dealt with in the first place , For example, service downtime … Secondly, the stability of resources , Just imagine , If one day you rely on a very important module suddenly deleted by the author , Is that the end of the calf , After all, what we do a lot of time is “ si ”, Once this happens , Basically blind . If there's a private warehouse , The above problems can be calmly faced with , Effectively guarantee business stability ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"2. Privacy "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Every company has modules that are strongly related to their business , Or personalized transformation of some open source modules , The modified module only meets the business scenarios of our company , We don't want to release these modules to a public repository , Then you can publish it to your own private warehouse and share it within the company ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"3. Security "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" With a private warehouse , Can be in npm The quality and safety of modules should be improved , Can effectively prevent malicious code attacks ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Sum up , It's absolutely necessary to build a private warehouse for your company , It's not a show . Of course , If your company compares mini, The need for the above points is not so urgent , It's also good to use public warehouses . But when the company grows to a certain size , In the foreseeable future , It's time to build your own private warehouse ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":" How to build private npm Warehouse "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" There are many mature open source solutions , It's a good idea to choose to stand on the shoulders of giants . Choose here  "},{"type":"link","attrs":{"href":"https:\/\/www.npmjs.com\/package\/cnpmjs.org","title":"xxx","type":null},"content":[{"type":"text","text":"cnpmjs.org"}]},{"type":"text","text":"  programme , There are three reasons. :"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"numberedlist","attrs":{"start":null,"normalizeStart":1},"content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":" At present, large domestic factories like Taobao also choose it , Enough to prove its reliability and stability "}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":" Extensibility is strong "}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":" Configuration diversification "}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":4,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Of course, the disadvantages are not without , The deployment is so complicated ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":" preparation "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" The troops did not move , Gateway leading , Since it's building enterprise applications , The basic environment needs to be prepared ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Linux The server "}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"node Environmental Science "}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" database ( Mysql )"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"nginx"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" That's about it , If you just get familiar with , Let's play . You don't have to use Linux The server ,Windows It's OK , But if it's an online application , Recommended or used Linux The server , After all Linux The stability of the system is there ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" The following example is in the cloud server (Ubuntu) The complete ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":" install "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":" install cnpmjs.org"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Recommended by git take cnpmjs.org The source code of the project is cloned to a local directory of the server . Or put the code fork To oneself git After warehouse , And then deploy based on the internal warehouse , In this way, it is convenient to carry out personalized transformation of the source code ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"git clone https:\/\/github.com\/cnpm\/cnpmjs.org.git"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Installation project dependency :"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"npm i"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" After installation, find the configuration file in the root directory of the project  "},{"type":"codeinline","content":[{"type":"text","text":"config\/index.js"}]},{"type":"text","text":" , There are a lot of configuration files here , At first, you can just focus on the following items ,"},{"type":"link","attrs":{"href":"https:\/\/gitee.com\/199253\/cnpmjs\/blob\/master\/config\/index.js","title":"xxx","type":null},"content":[{"type":"text","text":" Detailed configuration "}]},{"type":"text","text":"  Poke it here ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Service access port "}]}]}]},{"type":"codeblock","attrs":{"lang":"javascript"},"content":[{"type":"text","text":"registryPort: 7001,         \/\/ Warehouse service access port \nwebPort: 7002,              \/\/web Site access port \nbindingHost: '',   \/\/ Listen to bound Host, Default 127.0.0.1, You can access the Internet comment , In general, we don't expose our internal ports , Can be in nginx Make a turn on the floor "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Database configuration "}]}]}]},{"type":"codeblock","attrs":{"lang":"javascript"},"content":[{"type":"text","text":"database: {\n  db: 'npm', Database name \n  username: 'admin',\/\/ user \n  password: 'admin123',\/\/ password \n  \/\/  Database type \n  \/\/ -  At present, we support  'mysql', 'sqlite', 'postgres', 'mariadb'\n  dialect: 'mysql',\/\/ The default is sqlite, I choose the mysql\n  host: '127.0.0.1', \/\/ Database service address \n  port: 3306,    \/\/  port \n  \/\/  The database connection pool is configured by default \n  \/\/  Currently only supported   mysql  and  postgresql (since v1.5.0)\n  pool: {\n    maxConnections: 10,\n    minConnections: 0,\n    maxIdleTime: 30000\n  },\n  ...\/\/ Don't pay attention to the rest for the time being \n},\n"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Whether to enable private mode "}]}]}]},{"type":"codeblock","attrs":{"lang":"javascript"},"content":[{"type":"text","text":"enablePrivate: false,\/\/ Not enabled by default "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" In private mode , Only administrators can publish modules . Non administrator release module name must be named with scopes The beginning of a field, for example :"},{"type":"codeinline","content":[{"type":"text","text":"@catfly\/packagename"}]},{"type":"text","text":"."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Publish prefix "}]}]}]},{"type":"codeblock","attrs":{"lang":"javascript"},"content":[{"type":"text","text":"scopes: ['@catfly'],"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" This is used in conjunction with enabling non private mode , This item must be configured to publish in non private mode ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Administrator account configuration "}]}]}]},{"type":"codeblock","attrs":{"lang":"javascript"},"content":[{"type":"text","text":"admins: {\n  fengmk2: 'fengmk2@gmail.com',\n  admin: 'admin@cnpmjs.org',\n  dead_horse: 'dead_horse@qq.com',\n}\n"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" If private mode is enabled , Only users in this configuration item can publish private packages . As for other configuration items, don't pay attention to , Later, it is gradually configured according to the needs ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Synchronous mode "}]}]}]},{"type":"codeblock","attrs":{"lang":"javascript"},"content":[{"type":"text","text":"\/\/  Synchronization mode options \n\/\/ none:  Out of sync , Only manage private modules uploaded by users , Common modules are obtained directly from upstream \n\/\/ exist:  Only synchronize modules that already exist in the database \n\/\/ all:  Synchronize all sources at the same time registry Module \nsyncModel:'exist'\n"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":" database "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" I choose the mysql , How to install it is not described here mysql 了 , Please... If you need to "},{"type":"link","attrs":{"href":"https:\/\/www.runoob.com\/mysql\/mysql-install.html","title":"xxx","type":null},"content":[{"type":"text","text":" Poke it here "}]},{"type":"text","text":" . Of course, you can also choose other databases , At present, we support mysql、 sqlite、 postgres、 mariadb, The default is sqlite."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" First check the database service status , Make sure the database service is OK :"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/ae\/ae5e623bc197000c8b35fc76b6b76e48.png","alt":"Image","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Log in to the database "}]}]}]},{"type":"codeblock","attrs":{"lang":"javascript"},"content":[{"type":"text","text":"mysql -u root -p test123456"}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Create database "}]}]}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"create database npm;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Check the database list :"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/a4\/a4feb6c40e369205d5196308f1bc063c.webp","alt":"Image","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Create database tables "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"cnpmjs.org project docs The directory has provided us with the script to create the database db.sql. perform :"}]}]}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"source docs\/db.sql;"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" By default, the current operation path is in cnpmjs.org Under the project , If not , Please use db.sql The absolute path of ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" View results :"}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/62\/6268e3ef52cbd6f08c5814dfc994f95f.webp","alt":"Image","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" After the first two steps , You can run the project and have a look . Because we passed git Cloned , So you need to enter the project directory and execute the command to start the service "}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"npm run start"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" After successful startup , visit web page , Found in the previous configuration file web port 7002 I can't visit ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" This is because of the server firewall , You can choose to turn off the firewall , But this is not recommended ; The other is to open the specified port ."}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"iptables -A INPUT -p tcp --drop -j 7002 DROP"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" If you are using a cloud server , You need to go to the cloud service console , New security group , Open the exposed port ."}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/45\/4544c9e08ad9455df765b57e67c226a1.webp","alt":"Image","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" After the port is opened , visit web page :xxx.xxx.xxx.xx:7002, You can see the familiar deployment locally cnpm Page ."}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/fa\/fa776f6e1bf875f401e05d65792bb506.webp","alt":"Image","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" You can see from the address above , Using the domain name , It's not for use IP+ Port form , Because as an enterprise application ,IP+ The way ports work is like streaking , It is suggested to use domain name . I have added a sub domain name under my own cloud service domain name management ."}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/4d\/4d4cb744bf19ac7f9c18e900dab2c9a9.webp","alt":"Image","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Then configure nginx take IP Bind to the domain name , Use the default 80 port , Try not to connect the real port of private warehouse service with IP Exposed . By the way nginx Let's talk about the configuration , If you can accept IP+ The way the port is accessed , You can skip the next step ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"nginx To configure "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" If not installed nginx,"},{"type":"text","marks":[{"type":"strong"}],"text":" Poke it here "},{"type":"text","text":" (https:\/\/www.runoob.com\/linux\/nginx-install-setup.html). find nginx The configuration file , stay conf.d New folder information npm.conf The configuration file , This function is clear and clear , Because a lot of times nginx Not just acting as a service ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"lua"},"content":[{"type":"text","text":"server {\n  listen  80;\n  server_name www.mirrors.catfly.vip;\n  #charset koi8-r;\n  #access_log  logs\/host.access.log  main;\n  location \/ { \n    proxy_pass http:\/\/127.0.0.1:7002\/; # Proxy to cnpmjs.org Provided web service \n    proxy_set_header        X-Real-IP $remote_addr;\n  }\n  location \/registry\/ {\n    proxy_pass http:\/\/127.0.0.1:7001\/; #  Proxy to cnpmjs.org Registration services provided by \n    proxy_set_header X-Real-IP $remote_addr;\n    proxy_set_header Host $host;\n    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n  }\n  #error_page  404              \/404.html;\n  # redirect server error pages to the static page \/50x.html\n  # error_page   500 502 503 504  \/50x.html;\n  location = \/50x.html {\n    root   html;\n  }\n}\n"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" restart nginx:"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"service nginx restart"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Check nginx state , Prevent configuration errors , Cause restart failure ."}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/d9\/d9fc3e8ba034a7d4593c60ebb77fe5ba.webp","alt":"Image","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Build and deploy through the above environment , The basic work is done , Let's start to verify the function ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":" functional verification "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" It is recommended to install one before verification npm Source management module nrm , With it, we can switch freely between various sources ."}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"npm i nrm -g"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Add our own private source to nrm In the source list ."}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"nrm add catfly http:\/\/www.mirrors.catfly.vip\/registry"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Switch to private sources :"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"nrm use catfly"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/84\/84fda80585f36d7768d84e990c31eb89.webp","alt":"Image","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" At this time, local execution npm When operating, we will find our own private address ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"numberedlist","attrs":{"start":1,"normalizeStart":1},"content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":" Private package release "}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Registered users :"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"npm adduser"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/a6\/a683e34b2ed341c80db0664e5430562a.webp","alt":"Image","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Log in to the private warehouse :"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"npm login"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/d6\/d60bc173af6daef14d660820657da370.webp","alt":"Image","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" After successful login , Release npm, Execute in the prepared module directory :"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"npm publish"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" There may be all kinds of mistakes at this time , Mainly 403 Permission problems , Because of different requirements of private warehouse , for example :"}]},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" In non private mode (enablePrivate: false) Next , When users don't have administrator rights , The module name prefix must be specified in the configuration scope, If it doesn't exist or scopes This is not included in scope You're going to report a mistake ."}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" In private mode (enablePrivate: true) Next , If the user is not in the profile admins in , The publish operation is not allowed , On the contrary, if , Then his authority is very large , Not only can it be published, but it can also be deleted . So don't let the administrator account overflow in the real scene ."}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"numberedlist","attrs":{"start":2,"normalizeStart":2},"content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":" Package download installation "}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" After publishing successfully , Try to install the published private package :"}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"npm i xxxxx"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" No problem ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"numberedlist","attrs":{"start":3,"normalizeStart":3},"content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":"Web The workbench "}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":4,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Access to private warehouses web Site "}]},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/infoq\/66\/661edb1b355c2756dcd70ce332b5f2b5.webp","alt":"Image","title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Through this Sites can publish private packages 、 Delete and download for statistics , Private package search is also available . You can also deal with this web Personalized transformation of the site . Code 、 The data is on our side , How to make and how to make ."}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"horizontalrule"},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" The first figure :Unsplash"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" author : Little flying cat "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" original text :https:\/\/mp.weixin.qq.com\/s\/Q9JSBXx7eiq3GuAvg1itIw"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" original text : Every minute teaches you how to build an enterprise class npm Private warehouse "}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" source : Front end team of Zhengcai cloud - WeChat official account [ID:Zoo-Team]"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" Reprint : The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source ."}]}]}

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/04/20210401131200741s.html

随机推荐