@@ -5,6 +5,9 @@ import { resolveBuiltinPresets } from 'unimport'
55import { resolve } from 'pathe'
66import { colors } from 'consola/utils'
77import { logger } from '@nuxt/kit'
8+ import type { Nitro } from 'nitropack'
9+ import destr from 'destr'
10+ import { snakeCase } from 'scule'
811
912import type { ModuleOptions } from '@nuxt/schema'
1013import type { AutoImportsWithMetadata , HookInfo , NuxtDevtoolsServerContext , ServerFunctions } from '../types'
@@ -75,6 +78,42 @@ export function setupGeneralRPC({ nuxt, options, refresh, openInEditorHooks }: N
7578 getServerConfig ( ) {
7679 return nuxt . options
7780 } ,
81+ getServerRuntimeConfig ( ) {
82+ // Ported from https://github.com/unjs/nitro/blob/88e79fcdb2a024c96a3d1fd272d0acbff0405013/src/runtime/config.ts#L31
83+ // Since this operation happends on the Nitro runtime
84+ const ENV_PREFIX = 'NITRO_'
85+ const ENV_PREFIX_ALT = 'NUXT_'
86+
87+ function _getEnv ( key : string ) {
88+ const envKey = snakeCase ( key ) . toUpperCase ( )
89+ return destr ( process . env [ ENV_PREFIX + envKey ] ?? process . env [ ENV_PREFIX_ALT + envKey ] )
90+ }
91+
92+ function _isObject ( input : unknown ) {
93+ return typeof input === 'object' && ! Array . isArray ( input )
94+ }
95+
96+ function _applyEnv ( obj : any , parentKey = '' ) {
97+ for ( const key in obj ) {
98+ const subKey = parentKey ? `${ parentKey } _${ key } ` : key
99+ const envValue = _getEnv ( subKey )
100+ if ( _isObject ( obj [ key ] ) ) {
101+ if ( _isObject ( envValue ) )
102+ obj [ key ] = { ...obj [ key ] , ...( envValue as any ) }
103+
104+ _applyEnv ( obj [ key ] , subKey )
105+ }
106+ else {
107+ obj [ key ] = envValue ?? obj [ key ]
108+ }
109+ }
110+ return obj
111+ }
112+
113+ const runtime = { ...nuxt . options . runtimeConfig }
114+ _applyEnv ( runtime )
115+ return runtime
116+ } ,
78117 getModuleOptions ( ) : ModuleOptions {
79118 return options
80119 } ,
0 commit comments