# myfams-url-module-container

> 为接口调用提供不同环境的主机

Latest version **2.1.21** (published 2021-08-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install myfams-url-module-container
pnpm add myfams-url-module-container
yarn add myfams-url-module-container
bun add myfams-url-module-container
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.21 |
| Published | 2021-08-13 |
| First published | 2021-08-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | liupei |
| Maintainers | rofound |

## Links

- npm: https://www.npmjs.com/package/myfams-url-module-container
- Repository: http://192.168.1.57/frontend/myfams-url-module-container
- npm.io page: https://npm.io/package/myfams-url-module-container

## Recent versions

- 2.1.21 (latest) — 2021-08-13

## README

<p align="center"><a href="https://vuejs.org" target="_blank" rel="noopener noreferrer"><img width="100" src="http://192.168.1.40:8080/myfams/static/assets/login/flag.png" alt="Vue logo"></a></p>

<h2 align="center">api对象生成器</h2>

### 特性

  - 可以按照不同环境的选择不同的主机（baseUrl）, 并提供一个默认主机

### 未来可能的特性

  - 根据不同的环境生成配置不同的环境的默认值

### 步骤说明

  1. 配置公司私有镜像
  2. 安装
  3. 参考使用环境说明

### 配置公司私有镜像

```shell
npm set registry http://192.168.1.79:4873
```

or

```shell
yarn config set registry http://192.168.1.79:4873
```

### 安装

```shell
npm i myfams-url-module-container
```

or

```shell
yarn add myfams-url-module-container
```

### webpack 环境下、vuejs单文件组件下使用

```js
import urlFactory from 'myfams-url-module-container'
const createUrls = urlFactory({
  globalBaseUrl: 'hello.is.com', // 如果所有环境都不匹配则赋值该默认值
  NODE_ENV: process.env.NODE_ENV
})
const apis = createUrls([{
  url: '/rest/api/getList',
  baseUrlMap: {
    'production': 'http://localhost:8080/myfams',
    'development': 'http://localhost:8080',
    'development-local': 'http://localhost:8081',
    'test': 'http://localhost:8089'
  },
  apiName: 'getList',
  comment: '' // 接口说明，方便后续直接导出文档
}])
console.log(apis);
// 输出 { getList: '//hello.www.com/rest/api/getList' }
```

### nodejs环境下使用

```js
const configFactory = require('myfams-url-module-container')
const allApi = [
  {
    url: '/rest/api/getList',
    baseUrlMap: {
      'production': 'http://localhost:8080/myfams',
      'development': 'http://localhost:8080',
      'development-local': 'http://localhost:8081',
      'test': 'http://localhost:8089'
    },
    comment: ''// 接口说明，方便后续直接导出文档
  }
]
const createApis = configFactory({
  globalBaseUrl: '//hello.www.com',// 如果所有环境都不匹配则赋值该默认值
  NODE_ENV: process.env.NODE_ENV
})
const apis = createApis(allApi)
console.log(apis);
// 输出 { getList: '//hello.www.com/rest/api/getList' }
```

---
_Source: https://npm.io/package/myfams-url-module-container · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
