Comparing version 0.0.12 to 0.0.13
@@ -0,1 +1,8 @@ | ||
## [0.0.13](https://github.com/posva/mande/compare/v0.0.12...v0.0.13) (2020-07-27) | ||
### Bug Fixes | ||
- **nuxt:** avoid hot reload error ([d47e46d](https://github.com/posva/mande/commit/d47e46d6a8817c075be9398d0102aa9d886af29e)) | ||
- ignore some headers when proxying ([f99d313](https://github.com/posva/mande/commit/f99d313c61e360ea5e6a5f19ce4d198e1fd4875a)) | ||
## [0.0.12](https://github.com/posva/mande/compare/v0.0.11...v0.0.12) (2020-07-23) | ||
@@ -2,0 +9,0 @@ |
/*! | ||
* mande v0.0.11 | ||
* mande v0.0.12 | ||
* (c) 2020 Eduardo San Martin Morote | ||
@@ -4,0 +4,0 @@ * @license MIT |
/*! | ||
* mande v0.0.11 | ||
* mande v0.0.12 | ||
* (c) 2020 Eduardo San Martin Morote | ||
@@ -4,0 +4,0 @@ * @license MIT |
/*! | ||
* mande v0.0.11 | ||
* mande v0.0.12 | ||
* (c) 2020 Eduardo San Martin Morote | ||
@@ -4,0 +4,0 @@ * @license MIT |
/*! | ||
* mande v0.0.11 | ||
* mande v0.0.12 | ||
* (c) 2020 Eduardo San Martin Morote | ||
@@ -4,0 +4,0 @@ * @license MIT |
/*! | ||
* mande v0.0.11 | ||
* mande v0.0.12 | ||
* (c) 2020 Eduardo San Martin Morote | ||
@@ -4,0 +4,0 @@ * @license MIT |
import path from 'path' | ||
export default function NuxtMandeModule() { | ||
const DEFAULT_OPTIONS = { | ||
proxyHeadersIgnore: [ | ||
'accept', | ||
'host', | ||
'cf-ray', | ||
'cf-connecting-ip', | ||
'content-length', | ||
'content-md5', | ||
'content-type', | ||
], | ||
} | ||
/** @type {import('@nuxt/types').Module} */ | ||
const MandeModule = function NuxtMandeModule(localOptions) { | ||
// TODO: merge arrays properly. There is probably a package to handle this | ||
const options = { | ||
...DEFAULT_OPTIONS, | ||
...localOptions, | ||
} | ||
this.addPlugin({ | ||
src: path.resolve(__dirname, 'plugin.js'), | ||
fileName: 'mande.js', | ||
options, | ||
}) | ||
} |
@@ -0,1 +1,2 @@ | ||
/** @type {import('@nuxt/types').Plugin} */ | ||
@@ -7,3 +8,18 @@ export default (ctx, inject) => { | ||
(api) => { | ||
api.options.headers = { ...api.options.headers, ...ctx.req.headers } | ||
// the plugin can be called during dev in client side with no context | ||
if (!ctx.req) return | ||
const reqHeaders = { ...ctx.req.headers } | ||
// @ts-ignore | ||
for (let header of <%= serialize(options.proxyHeadersIgnore) %>) { | ||
delete reqHeaders[header] | ||
} | ||
api.options.headers = { ...api.options.headers, ...reqHeaders } | ||
if (process.server) { | ||
// Don't accept brotli encoding because Node can't parse it | ||
api.options.headers['accept-encoding'] = 'gzip, deflate' | ||
} | ||
}, | ||
@@ -10,0 +26,0 @@ ...args |
{ | ||
"name": "mande", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "Some awesome description", | ||
@@ -5,0 +5,0 @@ "main": "dist/mande.common.js", |
@@ -122,3 +122,18 @@ # mande [![Build Status](https://badgen.net/circleci/github/posva/mande/master)](https://circleci.com/gh/posva/mande) [![npm package](https://badgen.net/npm/v/mande)](https://www.npmjs.com/package/mande) [![coverage](https://badgen.net/codecov/c/github/posva/mande/master)](https://codecov.io/github/posva/mande) [![thanks](https://badgen.net/badge/thanks/♥/pink)](https://github.com/posva/thanks) | ||
} | ||
``` | ||
To make Mande work on Server, make sure to provide a `fetch` polyfill and to use full URLs and not absolute URLs starting with `/`. For example, using `node-fetch`, you can do: | ||
```js | ||
export const BASE_URL = process.server | ||
? process.env.NODE_ENV !== 'production' | ||
? 'http://localhost:3000' | ||
: 'https://example.com' | ||
// on client, do not add the domain, so urls end up like `/api/something` | ||
: '' | ||
const fetchPolyfill = process.server ? require('node-fetch') : fetch | ||
const contents = mande(BASE_URL + '/api', {}, fetchPolyfill) | ||
``` | ||
## API | ||
@@ -125,0 +140,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32121
550
151