-
-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ssg): Ignore Dynamic Route #1990
Changes from 3 commits
4cb8aa8
3869793
d129cf3
caadb37
966dce9
ef516e3
422aba6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -78,17 +78,41 @@ export const fetchRoutesContent = async < | |||
const baseURL = 'http://localhost' | ||||
|
||||
for (const route of inspectRoutes(app)) { | ||||
if (route.isMiddleware) continue | ||||
if (route.isMiddleware || isDynamicRoute(route.path)) continue | ||||
|
||||
const url = new URL(route.path, baseURL).toString() | ||||
const contentData = await fetchRouteContent(app, route.path, baseURL) | ||||
if (contentData) { | ||||
htmlMap.set(route.path, contentData) | ||||
} | ||||
} | ||||
|
||||
return htmlMap | ||||
} | ||||
|
||||
interface RouteContent { | ||||
content: string | ArrayBuffer | ||||
mimeType: string | ||||
} | ||||
|
||||
const fetchRouteContent = async <E extends Env = Env, S extends Schema = {}>( | ||||
app: Hono<E, S>, | ||||
path: string, | ||||
baseURL: string | ||||
): Promise<RouteContent | null> => { | ||||
try { | ||||
const url = new URL(path, baseURL).toString() | ||||
const response = await app.fetch(new Request(url)) | ||||
const mimeType = response.headers.get('Content-Type')?.split(';')[0] || 'text/plain' | ||||
const content = await parseResponseContent(response) | ||||
|
||||
htmlMap.set(route.path, { content, mimeType }) | ||||
return { content, mimeType } | ||||
} catch (error) { | ||||
console.error(`Error fetching content for path: ${path}`, error) | ||||
return null | ||||
} | ||||
} | ||||
|
||||
return htmlMap | ||||
const isDynamicRoute = (path: string): boolean => { | ||||
return /:\w+|\*/.test(path) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The determination of the named path parameters here is incorrect.
Line 55 in a00fc56
So you have to split the path with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed. |
||||
} | ||||
|
||||
/** | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should you include these
fetchRouteContent
things in this PR?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't need it, so I reverted it.