This commit is contained in:
2022-07-21 03:28:35 +00:00
parent d7c883d6df
commit 51b34b0e1d
30103 changed files with 4152204 additions and 23 deletions
+150
View File
@@ -0,0 +1,150 @@
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## [2.1.0](https://github.com/nuxt-community/proxy-module/compare/v2.0.1...v2.1.0) (2020-12-14)
### Features
* update module (typescript rewrite) ([c9dad3c](https://github.com/nuxt-community/proxy-module/commit/c9dad3c547759ca05413b6d85087e80e468297a5))
### [2.0.1](https://github.com/nuxt-community/proxy-module/compare/v2.0.0...v2.0.1) (2020-07-16)
### Bug Fixes
* skip module for nuxt build (fixes [#74](https://github.com/nuxt-community/proxy-module/issues/74)) ([50db85e](https://github.com/nuxt-community/proxy-module/commit/50db85eb5dd76dd20fe146b282cc082de721663f))
## [2.0.0](https://github.com/nuxt-community/proxy-module/compare/v1.3.3...v2.0.0) (2020-06-03)
### ⚠ BREAKING CHANGES
* Bumping major version as http-proxy-middleware may introduce some usage regressions
### Features
* bump to 2.x ([57eb492](https://github.com/nuxt-community/proxy-module/commit/57eb492c42cea6b6e90e4348065da308274fbc8a))
* upgrade to `http-proxy-middleware` 1.0.1 ([0277f6d](https://github.com/nuxt-community/proxy-module/commit/0277f6d0c753a73b2b4ab15223c1a5f9da0085ca))
### Bug Fixes
* **module:** use logger ([#40](https://github.com/nuxt-community/proxy-module/issues/40)) ([6bfbcad](https://github.com/nuxt-community/proxy-module/commit/6bfbcade52c364647c26084eb66a16ff6a7c7e11))
## [1.3.3](https://github.com/nuxt-community/proxy-module/compare/v1.3.2...v1.3.3) (2019-03-02)
### Bug Fixes
* **module:** generate warn if not SPA and increase coverage ([#31](https://github.com/nuxt-community/proxy-module/issues/31)) ([8baafc9](https://github.com/nuxt-community/proxy-module/commit/8baafc9))
## [1.3.2](https://github.com/nuxt-community/proxy-module/compare/v1.3.1...v1.3.2) (2019-02-18)
### Bug Fixes
* skip generate warn for now because of SPA ([7b23097](https://github.com/nuxt-community/proxy-module/commit/7b23097))
<a name="1.3.1"></a>
## [1.3.1](https://github.com/nuxt-community/proxy-module/compare/v1.3.0...v1.3.1) (2018-10-30)
### Bug Fixes
* add hint for "universal" mode only ([#10](https://github.com/nuxt-community/proxy-module/issues/10)) ([c78b122](https://github.com/nuxt-community/proxy-module/commit/c78b122))
<a name="1.3.0"></a>
# [1.3.0](https://github.com/nuxt-community/proxy-module/compare/v1.2.4...v1.3.0) (2018-10-29)
### Features
* upgrade dependencies ([331fa23](https://github.com/nuxt-community/proxy-module/commit/331fa23))
<a name="1.2.4"></a>
## [1.2.4](https://github.com/nuxt-community/proxy-module/compare/v1.2.3...v1.2.4) (2018-03-31)
<a name="1.2.3"></a>
## [1.2.3](https://github.com/nuxt-community/proxy-module/compare/v1.2.2...v1.2.3) (2018-03-31)
### Bug Fixes
* hide debug logs ([66c1905](https://github.com/nuxt-community/proxy-module/commit/66c1905))
<a name="1.2.2"></a>
## [1.2.2](https://github.com/nuxt-community/proxy-module/compare/v1.2.1...v1.2.2) (2018-03-31)
<a name="1.2.1"></a>
## [1.2.1](https://github.com/nuxt-community/proxy-module/compare/v1.2.0...v1.2.1) (2018-03-31)
<a name="1.2.0"></a>
# [1.2.0](https://github.com/nuxt-community/proxy-module/compare/v1.1.4...v1.2.0) (2018-03-31)
<a name="1.1.4"></a>
## 1.1.4 (2018-01-28)
<a name="1.1.3"></a>
## [1.1.3](https://github.com/nuxt/modules/compare/@nuxtjs/proxy@1.1.2...@nuxtjs/proxy@1.1.3) (2017-11-20)
**Note:** Version bump only for package @nuxtjs/proxy
<a name="1.1.2"></a>
## [1.1.2](https://github.com/nuxt/modules/compare/@nuxtjs/proxy@1.1.1...@nuxtjs/proxy@1.1.2) (2017-09-05)
### Bug Fixes
* **proxy:** disable prefix ([3e2e70f](https://github.com/nuxt/modules/commit/3e2e70f))
<a name="1.1.1"></a>
## [1.1.1](https://github.com/nuxt/modules/compare/@nuxtjs/proxy@1.1.0...@nuxtjs/proxy@1.1.1) (2017-06-09)
### Bug Fixes
* **plugin:** normalize array alternative form path ([811b5a9](https://github.com/nuxt/modules/commit/811b5a9))
<a name="1.1.0"></a>
# 1.1.0 (2017-06-07)
### Bug Fixes
* **proxy:** normalize target in object mode ([e9d4026](https://github.com/nuxt/modules/commit/e9d4026))
### Features
* proxy module ([6dfca4d](https://github.com/nuxt/modules/commit/6dfca4d))
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) Nuxt Community
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Generated Vendored Executable
+126
View File
@@ -0,0 +1,126 @@
# @nuxtjs/proxy
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![codecov][codecov-src]][codecov-href]
[![license][license-src]][license-href]
> Proxy support for nuxt server
[📖 **Release Notes**](./CHANGELOG.md)
## Features
✓ Path rewrites
✓ Host based router (useful for staging/test)
✓ Logs / Proxy Events
✓ WebSockets
✓ Auth / Cookie
✓ ...See [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware) docs
⚠ Does not work in generated/static mode!
## Setup
1. Add `@nuxtjs/proxy` dependency to your project
```bash
yarn add @nuxtjs/proxy # or npm install @nuxtjs/proxy
```
2. Add `@nuxtjs/proxy` to the `modules` section of `nuxt.config.js`
```js
{
modules: [
// Simple usage
'@nuxtjs/proxy',
// With options
['@nuxtjs/proxy', { pathRewrite: { '^/api' : '/api/v1' } }]
]
}
```
- Define as many as proxy middleware you want in `proxy` section of `nuxt.config.js` (See [proxy](#proxy) section below)
## Options
- `changeOrigin` and `ws` options are enabled by default.
[optional] You can provide default options to all proxy targets by passing options to module options.
## `proxy`
You can provide proxy config using either object or array.
### Array Config
You can use [shorthand syntax](https://github.com/chimurai/http-proxy-middleware#shorthand) to configure proxy:
```js
{
proxy: [
// Proxies /foo to http://example.com/foo
'http://example.com/foo',
// Proxies /api/books/*/**.json to http://example.com:8000
'http://example.com:8000/api/books/*/**.json',
// You can also pass more options
[ 'http://example.com/foo', { ws: false } ]
]
}
```
### Object Config
Keys are [context](https://github.com/chimurai/http-proxy-middleware#context-matching)
```js
{
proxy: {
// Simple proxy
'/api': 'http://example.com',
// With options
'/api2': { target: 'http://example.com', ws: false },
// Proxy to backend unix socket
'/api3': {
changeOrigin: false,
target: { socketPath: '/var/run/http-sockets/backend.sock' }
}
}
}
```
## Development
1. Clone this repository
2. Install dependencies using `yarn install` or `npm install`
3. Start development server using `npm run dev`
## License
[MIT License](./LICENSE)
Copyright (c) Nuxt Community
<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/@nuxtjs/proxy/latest.svg?style=flat-square
[npm-version-href]: https://npmjs.com/package/@nuxtjs/proxy
[npm-downloads-src]: https://img.shields.io/npm/dt/@nuxtjs/proxy.svg?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/@nuxtjs/proxy
[codecov-src]: https://img.shields.io/codecov/c/github/nuxt-community/proxy-module.svg?style=flat-square
[codecov-href]: https://codecov.io/gh/nuxt-community/proxy-module
[license-src]: https://img.shields.io/npm/l/@nuxtjs/proxy.svg?style=flat-square
[license-href]: https://npmjs.com/package/@nuxtjs/proxy
+18
View File
@@ -0,0 +1,18 @@
import { Module } from '@nuxt/types';
import { Options, Filter } from 'http-proxy-middleware';
declare type ProxyContext = Filter | Options;
declare type ProxyOptionsObject = {
[target: string]: Options;
};
declare type ProxyOptionsArray = Array<[ProxyContext, Options?] | Options | string>;
declare type NuxtProxyOptions = ProxyOptionsObject | ProxyOptionsArray;
declare module '@nuxt/types' {
interface Configuration {
proxy?: NuxtProxyOptions;
}
}
declare const proxyModule: Module<Options>;
export default proxyModule;
+57
View File
@@ -0,0 +1,57 @@
'use strict';
const httpProxyMiddleware = require('http-proxy-middleware');
function getProxyEntries(proxyOptions, defaults) {
const applyDefaults = (opts) => ({...defaults, ...opts});
const normalizeTarget = (input) => typeof input === "object" ? input : {target: input};
const proxyEntries = [];
if (!proxyOptions) {
return proxyEntries;
}
if (!Array.isArray(proxyOptions)) {
for (const key in proxyOptions) {
proxyEntries.push({
context: key,
options: applyDefaults(normalizeTarget(proxyOptions[key]))
});
}
return proxyEntries;
}
for (const input of proxyOptions) {
if (Array.isArray(input)) {
proxyEntries.push({
context: input[0],
options: applyDefaults(normalizeTarget(input[1]))
});
} else {
proxyEntries.push({
context: input,
options: applyDefaults()
});
}
}
return proxyEntries;
}
const proxyModule = function(options2) {
const nuxt = this.nuxt;
if (!nuxt.options.server || !nuxt.options.proxy) {
return;
}
const defaults = {
changeOrigin: true,
ws: true,
...options2
};
const proxyEntries = getProxyEntries(nuxt.options.proxy, defaults);
for (const proxyEntry of proxyEntries) {
this.addServerMiddleware({
prefix: false,
handler: httpProxyMiddleware.createProxyMiddleware(proxyEntry.context, proxyEntry.options)
});
}
};
proxyModule.meta = require("../package.json");
module.exports = proxyModule;
+72
View File
@@ -0,0 +1,72 @@
{
"_args": [
[
"@nuxtjs/proxy@2.1.0",
"/home/node/nuxt"
]
],
"_from": "@nuxtjs/proxy@2.1.0",
"_id": "@nuxtjs/proxy@2.1.0",
"_inBundle": false,
"_integrity": "sha512-/qtoeqXgZ4Mg6LRg/gDUZQrFpOlOdHrol/vQYMnKu3aN3bP90UfOUB3QSDghUUK7OISAJ0xp8Ld78aHyCTcKCQ==",
"_location": "/@nuxtjs/proxy",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "@nuxtjs/proxy@2.1.0",
"name": "@nuxtjs/proxy",
"escapedName": "@nuxtjs%2fproxy",
"scope": "@nuxtjs",
"rawSpec": "2.1.0",
"saveSpec": null,
"fetchSpec": "2.1.0"
},
"_requiredBy": [
"/@nuxtjs/axios"
],
"_resolved": "https://registry.npmjs.org/@nuxtjs/proxy/-/proxy-2.1.0.tgz",
"_spec": "2.1.0",
"_where": "/home/node/nuxt",
"bugs": {
"url": "https://github.com/nuxt-community/proxy-module/issues"
},
"dependencies": {
"http-proxy-middleware": "^1.0.6"
},
"description": "proxy support for nuxt server",
"devDependencies": {
"@babel/preset-typescript": "^7.12.7",
"@nuxt/test-utils": "latest",
"@nuxt/types": "latest",
"@nuxtjs/eslint-config-typescript": "latest",
"eslint": "latest",
"jest": "latest",
"nuxt": "^2.14.11",
"siroc": "latest",
"standard-version": "latest"
},
"files": [
"dist"
],
"homepage": "https://github.com/nuxt-community/proxy-module#readme",
"license": "MIT",
"main": "dist/index.js",
"name": "@nuxtjs/proxy",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/nuxt-community/proxy-module.git"
},
"scripts": {
"build": "siroc build",
"dev": "nuxt test/fixture",
"lint": "eslint --ext .js,.vue,.ts .",
"release": "yarn test && standard-version && git push --follow-tags && npm publish",
"test": "yarn lint && jest"
},
"types": "dist/index.d.ts",
"version": "2.1.0"
}