-
-
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.
feat: add support to
@astrojs/cloudflare
directory deploy mode (#3806)
Co-authored-by: Matthew Phillips <matthew@skypack.dev> Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
- Loading branch information
1 parent
821074f
commit f4c571b
Showing
6 changed files
with
98 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/cloudflare': minor | ||
--- | ||
|
||
add support for compiling functions to a functions directory rather than `_worker.js` |
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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import './shim.js'; | ||
|
||
import type { SSRManifest } from 'astro'; | ||
import { App } from 'astro/app'; | ||
|
||
export function createExports(manifest: SSRManifest) { | ||
const app = new App(manifest, false) | ||
|
||
const onRequest = async ({ | ||
request, | ||
next, | ||
}: { | ||
request: Request; | ||
next: (request: Request) => void; | ||
}) => { | ||
const { origin, pathname } = new URL(request.url); | ||
|
||
// static assets | ||
if (manifest.assets.has(pathname)) { | ||
const assetRequest = new Request(`${origin}/static${pathname}`, request); | ||
return next(assetRequest); | ||
} | ||
|
||
let routeData = app.match(request, { matchNotFound: true }); | ||
if (routeData) { | ||
Reflect.set( | ||
request, | ||
Symbol.for('astro.clientAddress'), | ||
request.headers.get('cf-connecting-ip') | ||
); | ||
return app.render(request, routeData); | ||
} | ||
|
||
return new Response(null, { | ||
status: 404, | ||
statusText: 'Not found', | ||
}); | ||
}; | ||
|
||
return { onRequest }; | ||
} |