Skip to content

Commit 7d2a96c

Browse files
committed
feat(deps): look for runtimeConfig first
1 parent f2c815c commit 7d2a96c

File tree

4 files changed

+30
-31
lines changed

4 files changed

+30
-31
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"build": "nuxt-module-build",
4141
"play": "nr build && nuxi dev playground",
4242
"build:playground": "nuxi build playground",
43+
"preview:playground": "nuxi preview playground",
4344
"lint": "eslint .",
4445
"lint:fix": "eslint . --fix",
4546
"release": "bumpp --commit --push --tag && npm publish",
@@ -48,7 +49,6 @@
4849
"dependencies": {
4950
"@nuxt/kit": "3.0.0-rc.12",
5051
"dedent": "^0.7.0",
51-
"defu": "^6.0.0",
5252
"h3": "^0.8.5",
5353
"http-proxy-middleware": "^3.0.0-beta.0",
5454
"ohash": "^0.1.5",

playground/nuxt.config.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,32 @@ import Module from '../src/module'
44
// https://v3.nuxtjs.org/api/configuration/nuxt.config
55
export default defineNuxtConfig({
66
modules: [Module],
7-
proxy: {
8-
options: [
9-
{
10-
target: 'https://jsonplaceholder.typicode.com',
11-
changeOrigin: true,
12-
pathRewrite: {
13-
'^/api/todos': '/todos',
14-
'^/api/users': '/users',
7+
runtimeConfig: {
8+
proxy: {
9+
options: [
10+
{
11+
target: 'https://jsonplaceholder.typicode.com',
12+
changeOrigin: true,
13+
pathRewrite: {
14+
'^/api/todos': '/todos',
15+
'^/api/users': '/users',
16+
},
17+
pathFilter: [
18+
'/api/todos',
19+
'/api/users',
20+
],
1521
},
16-
pathFilter: [
17-
'/api/todos',
18-
'/api/users',
19-
],
20-
},
21-
{
22-
target: 'https://api.spacexdata.com/v5',
23-
changeOrigin: true,
24-
pathRewrite: {
25-
'^/api/launches': '/launches/latest',
22+
{
23+
target: 'https://api.spacexdata.com/v5',
24+
changeOrigin: true,
25+
pathRewrite: {
26+
'^/api/launches': '/launches/latest',
27+
},
28+
pathFilter: [
29+
'/api/launches',
30+
],
2631
},
27-
pathFilter: [
28-
'/api/launches',
29-
],
30-
},
31-
],
32-
},
32+
],
33+
},
34+
}
3335
})

pnpm-lock.yaml

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/module.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { fileURLToPath } from 'url'
22
import { addServerHandler, addTemplate, defineNuxtModule } from '@nuxt/kit'
33
import type { Options } from 'http-proxy-middleware'
44
import { join } from 'pathe'
5-
import { defu } from 'defu'
65
import dedent from 'dedent'
76
import { hash, objectHash } from 'ohash'
87

@@ -14,7 +13,7 @@ function createProxyMiddleware(buildDir: string, filename: string, options: Opti
1413
import { createProxyMiddleware } from 'nuxt-proxy/middleware'
1514
import { useRuntimeConfig } from '#imports'
1615
17-
export default createProxyMiddleware(useRuntimeConfig().proxy.options)
16+
export default createProxyMiddleware(${JSON.stringify(options)})
1817
`,
1918
})
2019

@@ -40,8 +39,8 @@ export default defineNuxtModule<ModuleOptions>({
4039
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
4140
nuxt.options.build.transpile.push(runtimeDir)
4241

43-
// Final resolved configuration
44-
const finalConfig = (nuxt.options.runtimeConfig.proxy = defu(nuxt.options.runtimeConfig.proxy, options)) as ModuleOptions
42+
// @ts-expect-error: Internal
43+
const finalConfig = (nuxt.options.runtimeConfig.proxy = nuxt.options.runtimeConfig.proxy || { options: options.options }) as ModuleOptions
4544

4645
if (Array.isArray(finalConfig.options)) {
4746
finalConfig.options.forEach((options) => {

0 commit comments

Comments
 (0)