2.5.8 • Published 4 months ago

@nuxt-alt/proxy v2.5.8

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Proxy module for Nuxt

Info

This serves as an alternative for @nuxtjs-alt/proxy. Please note that this is for nuxt 3 only. The config is similar to what vite has except that this one creates a physical file which is needed for production.

Setup

  1. Add @nuxt-alt/proxy dependency to your project
yarn add @nuxt-alt/proxy
  1. Add @nuxt-alt/proxy to the modules section of nuxt.config.ts
export default defineNuxtConfig({
    modules: [
        '@nuxt-alt/proxy'
    ],
    proxy: {
        /* module options */
    }
});

Options

proxies

  • Type: Object
  • Default: {}

debug

  • Type: Boolean
  • Default: false (false in prod | true in dev)

urls to proxy

experimental.listener

  • Type: Boolean
  • Default: false

Enable this to use a nitro plugin that tries to hook onto the server's request and grab the server to listen in production. This is untested in non-node environments.

Nitro hook available after enabling (only in production):

nitroApp.hooks.hook('listen:node', (server) => {})

Config Example

import { defineNuxtConfig } from 'nuxt/config'

export default defineNuxtConfig({
    modules: [
        '@nuxt-alt/proxy',
    ],
    proxy: {
        debug: false,
        experimental: {
            listener: false
        },
        proxies: {
            // string shorthand
            '/foo': 'http://localhost:4567',
            // with options
            '/api': {
                target: 'http://jsonplaceholder.typicode.com',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, '')
            },
            // with RegEx
            '^/fallback/.*': {
                target: 'http://jsonplaceholder.typicode.com',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/fallback/, ''),
                configure: (proxy, options, runtimeConfig) => {
                    // proxy will be an instance of 'http-proxy'
                },
            },
            // Using the proxy instance
            '/api': {
                target: 'http://jsonplaceholder.typicode.com',
                changeOrigin: true,
                configureWithEvent: (proxy, options, runtimeConfig, event, h3) => {
                    // proxy will be an instance of 'http-proxy'
                    // event will be an instance of the matched url
                    proxy.on('proxyReq', (proxyReq) => {
                        const cookies = h3.parseCookies(event)
                        console.log(cookies)
                    })
                }
            },
            // Proxying websockets or socket.io - Note this only works with `experimental.listener`
            '/socket.io': {
                target: 'ws://localhost:5173',
                ws: true
            }
        }
    }
})
2.5.8

4 months ago

2.5.6

4 months ago

2.5.5

4 months ago

2.5.0

4 months ago

2.5.2

4 months ago

2.5.1

4 months ago

2.5.4

4 months ago

2.5.3

4 months ago

2.4.9

5 months ago

2.4.8

5 months ago

2.4.7

6 months ago

2.4.6

6 months ago

2.3.0

9 months ago

2.4.1

6 months ago

2.3.2

8 months ago

2.4.0

6 months ago

2.3.1

8 months ago

2.4.3

6 months ago

2.4.2

6 months ago

2.4.5

6 months ago

2.4.4

6 months ago

2.3.0-beta.0

1 year ago

2.3.0-beta.1

1 year ago

2.3.0-beta.2

1 year ago

2.2.1

1 year ago

2.2.3

1 year ago

2.2.2

1 year ago

2.2.0

1 year ago

2.1.3

1 year ago