Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"eslint": "9.39.2",
"happy-dom": "^20.3.3",
"installed-check": "^9.3.0",
"ipx": "^3.1.1",
"ipx": "^4.0.0-alpha.1",
"jiti": "2.6.1",
"knip": "^5.82.1",
"nitropack": "^2.13.1",
Expand All @@ -89,7 +89,7 @@
"vue-tsc": "^3.2.2"
},
"optionalDependencies": {
"ipx": "^3.1.1"
"ipx": "^4.0.0-alpha.1"
},
"packageManager": "pnpm@10.28.1",
"resolutions": {
Expand Down
109 changes: 30 additions & 79 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 27 additions & 5 deletions src/runtime/server/routes/_ipx.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { fileURLToPath } from 'node:url'

import { createIPX, createIPXH3Handler, ipxFSStorage, ipxHttpStorage } from 'ipx'
import { createIPX, createIPXFetchHandler, ipxFSStorage, ipxHttpStorage } from 'ipx'
import type { IPXOptions } from 'ipx'
import { lazyEventHandler, useBase } from 'h3'
import { lazyEventHandler, defineEventHandler, getRequestURL, sendWebResponse } from 'h3'
import { isAbsolute } from 'pathe'
import type { NitroRuntimeConfig } from 'nitropack'

Expand All @@ -27,7 +27,29 @@ export default lazyEventHandler(() => {
}

const ipx = createIPX(ipxOptions)

const ipxHandler = createIPXH3Handler(ipx)
return useBase(opts.baseURL, ipxHandler)
const _handler = createIPXFetchHandler(ipx)

return defineEventHandler(async (event) => {
// Get the path after the base URL (e.g., /_ipx)
const url = getRequestURL(event)

// Strip the base URL prefix from the pathname
const baseURL = opts.baseURL || '/_ipx'
let pathname = url.pathname
if (pathname.startsWith(baseURL)) {
pathname = pathname.slice(baseURL.length) || '/'
}

// Create a new URL with the stripped pathname for IPX
const ipxURL = new URL(pathname + url.search, url.origin)

// Create a request with the modified URL
const request = new Request(ipxURL, {
method: event.method,
headers: event.headers,
})

const response = await _handler(request)
return sendWebResponse(event, response)
})
})
Loading