Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 0a74001

Browse files
committed
Fix: resolve API routes with encoded URI
1 parent c6dbd42 commit 0a74001

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

project.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export class Project {
221221
}
222222

223223
async callAPI(req: ServerRequest, loc: { pathname: string, search?: string }): Promise<APIHandler | null> {
224-
const [url] = this.#apiRouting.createRouter(loc)
224+
const [url] = this.#apiRouting.createRouter({ ...loc, pathname: decodeURI(loc.pathname) })
225225
if (url.pagePath != '') {
226226
const moduleID = url.pagePath + '.js'
227227
if (this.#modules.has(moduleID)) {
@@ -1555,7 +1555,8 @@ function fixImportUrl(importUrl: string): string {
15551555
if (isRemote) {
15561556
return '/-/' + url.hostname + (url.port ? '/' + url.port : '') + pathname + ext
15571557
}
1558-
return pathname + ext
1558+
const result = pathname + ext
1559+
return !isRemote && importUrl.startsWith('/api/') ? decodeURI(result) : result;
15591560
}
15601561

15611562
/** get hash(sha1) of the content, mix current aleph.js version when the second parameter is `true` */

routing.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ export class Routing {
176176
}
177177

178178
export function getPagePath(moduleId: string): string {
179-
return util.trimSuffix(moduleId, '.js').replace(reMDExt, '').toLowerCase().replace(/\s+/g, '-').replace(/^\/pages\//, '/').replace(/\/?index$/, '/')
179+
const id = util.trimSuffix(moduleId, '.js').replace(reMDExt, '').toLowerCase().replace(/^\/pages\//, '/').replace(/\/?index$/, '/')
180+
return id.startsWith('/api/') ? id : id.replace(/\s+/g, '-')
180181
}
181182

182183
function matchPath(routePath: string, locPath: string): [Record<string, string>, boolean] {

0 commit comments

Comments
 (0)