1.1.2 • Published 1 year ago

nuxt-http-proxy v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Nuxt HTTP Proxy

Install

Command

~$ npm i nuxt-http-proxy

~$ yarn add nuxt-http-proxy

Nuxt config

export default defineNuxtConfig({
  modules: ['nuxt-http-proxy'],
})

Types

{
  "extends": "./.nuxt/tsconfig.json",
  "types": ["nuxt-http-proxy"]
}

Usage examples

Config key

export default defineNuxtConfig({
  proxy: [
    {
      target: 'https://run.mocky.io/v3/cce1f89f-f9a6-4ead-9184-c8b6a2b8bbc6',
      pathFilter: '/api/mocks',
      changeOrigin: true
    }
  ]
})

Runtime config

export default defineNuxtConfig({
  runtimeConfig: {
    proxy: [
      {
        target: 'https://run.mocky.io/v3/cce1f89f-f9a6-4ead-9184-c8b6a2b8bbc6',
        pathFilter: '/api/mocks',
        changeOrigin: true
      }
    ]
  }
})

Component

import { useFetch } from '#imports'

const { data } = await useFetch<{ status: string }>('http://localhost:3000/api/mocks')

Interfaces

/**
 * Options:
 * https://github.com/chimurai/http-proxy-middleware/blob/master/src/types.ts
 */

interface NuxtConfig {
  proxy?: Options[]
}