-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f612488
commit 7338066
Showing
8 changed files
with
82 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
import { NodeApp } from "astro/app/node" | ||
import type { RequestHandler } from "./types.js"; | ||
import { NodeApp } from 'astro/app/node'; | ||
import type { RequestHandler } from './types.js'; | ||
|
||
/** | ||
* Creates a Node.js http listener for on-demand rendered pages, compatible with http.createServer and Connect middleware. | ||
* If the next callback is provided, it will be called if the request does not have a matching route. | ||
* Intended to be used in both standalone and middleware mode. | ||
*/ | ||
export function createAppHandler(app: NodeApp): RequestHandler { | ||
return async (req, res, next, locals) => { | ||
const request = NodeApp.createRequest(req); | ||
const routeData = app.match(request); | ||
if (routeData) { | ||
const response = await app.render(request, { | ||
addCookieHeader: true, | ||
locals, | ||
routeData, | ||
}); | ||
await NodeApp.writeResponse(response, res); | ||
} else if (next) { | ||
return next(); | ||
} else { | ||
const response = await app.render(req); | ||
await NodeApp.writeResponse(response, res); | ||
} | ||
} | ||
return async (req, res, next, locals) => { | ||
const request = NodeApp.createRequest(req); | ||
const routeData = app.match(request); | ||
if (routeData) { | ||
const response = await app.render(request, { | ||
addCookieHeader: true, | ||
locals, | ||
routeData, | ||
}); | ||
await NodeApp.writeResponse(response, res); | ||
} else if (next) { | ||
return next(); | ||
} else { | ||
const response = await app.render(req); | ||
await NodeApp.writeResponse(response, res); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters