🐛 Testing out the new SSR cookie forward
This commit is contained in:
@@ -75,7 +75,7 @@ if (
|
|||||||
console.log("\nnpx nuxi module add icon\n")
|
console.log("\nnpx nuxi module add icon\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiBaseServer = useSolarNetworkUrl(true)
|
const apiBaseServer = useSolarNetworkUrl()
|
||||||
|
|
||||||
function toAbsoluteUrl(url: string | undefined) {
|
function toAbsoluteUrl(url: string | undefined) {
|
||||||
if (!url) return undefined
|
if (!url) return undefined
|
||||||
|
@@ -1,9 +1,16 @@
|
|||||||
// Solar Network aka the api client
|
// Solar Network aka the api client
|
||||||
import { keysToCamel, keysToSnake } from "~/utils/transformKeys"
|
import { keysToCamel, keysToSnake } from "~/utils/transformKeys"
|
||||||
|
|
||||||
export const useSolarNetwork = (withoutProxy = false) => {
|
export const useSolarNetwork = () => {
|
||||||
const apiBase = useSolarNetworkUrl(withoutProxy)
|
const apiBase = useSolarNetworkUrl()
|
||||||
const headers = process.server ? useRequestHeaders(["cookie"]) : {}
|
|
||||||
|
// Access SSR request event only on the server
|
||||||
|
const event = import.meta.server ? useRequestEvent() : null
|
||||||
|
|
||||||
|
// Forward cookies from the incoming request
|
||||||
|
const headers: HeadersInit = import.meta.server && event
|
||||||
|
? { cookie: event.headers.get('cookie') ?? '' }
|
||||||
|
: {}
|
||||||
|
|
||||||
return $fetch.create({
|
return $fetch.create({
|
||||||
baseURL: apiBase,
|
baseURL: apiBase,
|
||||||
@@ -11,7 +18,7 @@ export const useSolarNetwork = (withoutProxy = false) => {
|
|||||||
headers,
|
headers,
|
||||||
// Add Authorization header with Bearer token
|
// Add Authorization header with Bearer token
|
||||||
onRequest: ({ request, options }) => {
|
onRequest: ({ request, options }) => {
|
||||||
const side = process.server ? "SERVER" : "CLIENT"
|
const side = import.meta.server ? "SERVER" : "CLIENT"
|
||||||
console.log(`[useSolarNetwork] onRequest for ${request} on ${side}`)
|
console.log(`[useSolarNetwork] onRequest for ${request} on ${side}`)
|
||||||
|
|
||||||
// Transform request data from camelCase to snake_case
|
// Transform request data from camelCase to snake_case
|
||||||
@@ -28,7 +35,7 @@ export const useSolarNetwork = (withoutProxy = false) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useSolarNetworkUrl = (withoutProxy = false) => {
|
export const useSolarNetworkUrl = () => {
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
return config.public.apiBase
|
return config.public.apiBase
|
||||||
}
|
}
|
||||||
|
@@ -203,7 +203,7 @@ const username = computed(() => {
|
|||||||
|
|
||||||
// Use useFetch with the correct API URL to avoid router conflicts
|
// Use useFetch with the correct API URL to avoid router conflicts
|
||||||
const apiBase = useSolarNetworkUrl()
|
const apiBase = useSolarNetworkUrl()
|
||||||
const apiBaseServer = useSolarNetworkUrl(true)
|
const apiBaseServer = useSolarNetworkUrl()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data, error } = await useFetch(
|
const { data, error } = await useFetch(
|
||||||
|
@@ -27,7 +27,7 @@ function loadTheme(mode: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiBase = useSolarNetworkUrl(true)
|
const apiBase = useSolarNetworkUrl()
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const ui = SwaggerUIBundle({
|
const ui = SwaggerUIBundle({
|
||||||
|
@@ -7,7 +7,8 @@ export default withNuxt(
|
|||||||
rules: {
|
rules: {
|
||||||
"vue/multi-word-component-names": "off",
|
"vue/multi-word-component-names": "off",
|
||||||
"vue/no-v-html": "off",
|
"vue/no-v-html": "off",
|
||||||
"vue/html-self-closing": "off"
|
"vue/html-self-closing": "off",
|
||||||
|
"@typescript-eslint/ban-ts-comment": "off"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user