mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 17:35:57 +00:00
fix(nuxt3): enable legacy access to $config and static flags (#1588)
This commit is contained in:
parent
efe1fea1d1
commit
f3ff87c812
@ -2,7 +2,7 @@ import type { IncomingMessage, ServerResponse } from 'http'
|
||||
import type { App } from 'vue'
|
||||
import type { Component } from '@vue/runtime-core'
|
||||
import mockContext from 'unenv/runtime/mock/proxy'
|
||||
import type { NuxtApp } from './nuxt'
|
||||
import { NuxtApp, useRuntimeConfig } from './nuxt'
|
||||
|
||||
type Route = any
|
||||
type Store = any
|
||||
@ -92,19 +92,12 @@ function mock (warning: string) {
|
||||
}
|
||||
|
||||
const unsupported = new Set<keyof LegacyContext | keyof LegacyContext['ssrContext']>([
|
||||
'isClient',
|
||||
'isServer',
|
||||
'isStatic',
|
||||
'store',
|
||||
'target',
|
||||
'spa',
|
||||
'env',
|
||||
'modern',
|
||||
'fetchCounters'
|
||||
])
|
||||
|
||||
const todo = new Set<keyof LegacyContext | keyof LegacyContext['ssrContext']>([
|
||||
'isDev',
|
||||
'isHMR',
|
||||
// Routing handlers - needs implementation or deprecation
|
||||
'base',
|
||||
@ -123,6 +116,15 @@ const todo = new Set<keyof LegacyContext | keyof LegacyContext['ssrContext']>([
|
||||
|
||||
const routerKeys: Array<keyof LegacyContext | keyof LegacyContext['ssrContext']> = ['route', 'params', 'query']
|
||||
|
||||
const staticFlags = {
|
||||
isClient: process.client,
|
||||
isServer: process.server,
|
||||
isDev: process.dev,
|
||||
isStatic: undefined,
|
||||
target: 'server',
|
||||
modern: false
|
||||
}
|
||||
|
||||
export const legacyPlugin = (nuxtApp: NuxtApp) => {
|
||||
nuxtApp._legacyContext = new Proxy(nuxtApp, {
|
||||
get (nuxt, p: keyof LegacyContext | keyof LegacyContext['ssrContext']) {
|
||||
@ -149,9 +151,12 @@ export const legacyPlugin = (nuxtApp: NuxtApp) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (p === '$config') {
|
||||
// TODO: needs implementation
|
||||
return mock('Accessing runtime config is not yet supported in Nuxt 3.')
|
||||
if (p === '$config' || p === 'env') {
|
||||
return useRuntimeConfig()
|
||||
}
|
||||
|
||||
if (p in staticFlags) {
|
||||
return staticFlags[p]
|
||||
}
|
||||
|
||||
if (p === 'ssrContext') {
|
||||
|
Loading…
Reference in New Issue
Block a user