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

Commit c6dbd42

Browse files
committed
Fix: Lack of URL encoding processing #31
1 parent fd6627c commit c6dbd42

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
Thumbs.db
33
.aleph/
44
dist/
5+
6+
.vscode/launch.json

server.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ export async function start(appDir: string, port: number, isDev = false, reload
6363
continue
6464
}
6565

66+
// serve public files
67+
const filePath = path.join(project.appRoot, 'public', decodeURI(pathname))
68+
if (existsFileSync(filePath)) {
69+
const info = Deno.lstatSync(filePath)
70+
const lastModified = info.mtime?.toUTCString() ?? new Date().toUTCString()
71+
if (lastModified === req.headers.get('If-Modified-Since')) {
72+
resp.status(304).send('')
73+
continue
74+
}
75+
76+
const body = Deno.readFileSync(filePath)
77+
resp.setHeader('Last-Modified', lastModified)
78+
resp.send(body, getContentType(filePath))
79+
continue
80+
}
81+
6682
// serve APIs
6783
if (pathname.startsWith('/api/')) {
6884
project.callAPI(req, { pathname, search: url.search })
@@ -113,21 +129,6 @@ export async function start(appDir: string, port: number, isDev = false, reload
113129
}
114130
}
115131

116-
// serve public files
117-
const filePath = path.join(project.appRoot, 'public', pathname)
118-
if (existsFileSync(filePath)) {
119-
const info = await Deno.lstat(filePath)
120-
if (info.mtime?.toUTCString() === req.headers.get('If-Modified-Since')) {
121-
resp.status(304).send('')
122-
continue
123-
}
124-
125-
const body = await Deno.readFile(filePath)
126-
resp.setHeader('Last-Modified', info.mtime!.toUTCString())
127-
resp.send(body, getContentType(filePath))
128-
continue
129-
}
130-
131132
// ssr
132133
const [status, html] = await project.getPageHtml({ pathname, search: url.search })
133134
resp.status(status).send(html, 'text/html; charset=utf-8')

0 commit comments

Comments
 (0)