@radya/nuxt-proxy-party
v1.3.2
Published
Nuxt HTTP proxy based on H3
Downloads
393
Maintainers
Readme
Nuxt Proxy Party
Nuxt Proxy Party
is a module designed to simplify the process of creating proxies using h3
in your Nuxt application. This module allows you to easily define and manage proxy routes with custom handlers.
Installation
To install Nuxt Proxy Party
, run the following command:
yarn add -D @radya/nuxt-proxy-party
After installation, add the module to your nuxt.config.ts
:
export default defineNuxtConfig({
modules: ['@radya/nuxt-proxy-party'],
})
Configuration
To initialize the configuration file, run:
npx nuxt-proxy-party --init
This will create a default configuration file that you can modify to suit your needs.
Usage
To use Nuxt Proxy Party, you need to define your proxy routes within the server.config.ts
file:
Simple
import { getCookie } from 'h3'
import { defineProxyParty } from '#nuxt-proxy-party'
export default defineProxyParty([
{
name: 'bin',
baseUrl: '/api/bin',
target: 'https://httpbin.org',
},
])
With custom handler
import { getCookie } from 'h3'
import { defineProxyParty } from '#nuxt-proxy-party'
export default defineProxyParty([
{
name: 'bin',
baseUrl: '/api/bin',
target: 'https://httpbin.org',
handler: (event) => {
const token = getCookie(event, 'oauth/token')
if (token) {
event.node.req.headers.authorization = `Bearer ${token}`
}
},
},
])
Using Runtime Config
If you need to use runtime configuration, import it from #imports
:
import { useRuntimeConfig } from '#imports'
This allows you to access and use runtime configuration values in your proxy handler.
Contributing
We welcome contributions to Nuxt Proxy Party
. If you’d like to contribute, please follow these steps:
Enable Corepack: Ensure Corepack is enabled by running:
corepack enable
Install Dependencies: Install all necessary dependencies by running:
yarn install
Generate Type Stubs: Run the following command to generate type stubs:
yarn dev:prepare
Start Development Mode: Use the following command to start the playground in development mode:
yarn dev
This will set up your environment to develop and test Nuxt Proxy Party
.
License
This project is licensed under the MIT License. See the LICENSE file for more details.