-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added guide for query parameters and cookies
- Loading branch information
Showing
5 changed files
with
110 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
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,54 @@ | ||
--- | ||
title: Query Parameters | ||
description: Describes how to access query parameters on the server. | ||
--- | ||
|
||
## Setup | ||
|
||
Follow the [getting started guide](./getting-started) to create a new Astro project with the Astro AWS adapter. | ||
|
||
## Allowing Query Parameters | ||
|
||
In order to allow query parameters to be passed to your application, you must create a custom `CachePolicy` for the CloudFront distribution. The following example based on the getting started guide will allow all query parameters to be passed to your application. | ||
|
||
`lib/hello-cdk-stack.ts`: | ||
|
||
```ts | ||
import { Stack } from "aws-cdk-lib/core" | ||
import type { StackProps } from "aws-cdk-lib/core" | ||
import { AstroAWS } from "@astro-aws/constructs" | ||
import { | ||
CachePolicy, | ||
CacheQueryStringBehavior, | ||
} from "aws-cdk-lib/aws-cloudfront" | ||
|
||
export interface HelloCdkStackProps extends StackProps {} | ||
|
||
export class HelloCdkStack extends Stack { | ||
public constructor(scope: Construct, id: string, props: HelloCdkStackProps) { | ||
super(scope, id, props) | ||
|
||
const cachePolicy = new CachePolicy(this, "CachePolicy", { | ||
queryStringBehavior: CacheQueryStringBehavior.all(), | ||
}) | ||
|
||
new AstroAWS(this, "AstroAWS", { | ||
cdk: { | ||
// This configures all subpaths of /api. | ||
apiBehavior: { | ||
cachePolicy, | ||
}, | ||
// This configures everything excluding subpaths of /api. | ||
cloudfrontDistribution: { | ||
cachePolicy, | ||
}, | ||
}, | ||
websiteDir: "../my-astro-project", | ||
}) | ||
} | ||
} | ||
``` | ||
|
||
``` | ||
``` |
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,51 @@ | ||
--- | ||
title: Cookies | ||
description: Describes how to access cookies on the server. | ||
--- | ||
|
||
## Setup | ||
|
||
Follow the [getting started guide](./getting-started) to create a new Astro project with the Astro AWS adapter. | ||
|
||
## Allowing Cookies | ||
|
||
In order to allow cookies to be passed to your application, you must create a custom `CachePolicy` for the CloudFront distribution. The following example based on the getting started guide will allow all cookies to be passed to your application. | ||
|
||
`lib/hello-cdk-stack.ts`: | ||
|
||
```ts | ||
import { Stack } from "aws-cdk-lib/core" | ||
import type { StackProps } from "aws-cdk-lib/core" | ||
import { AstroAWS } from "@astro-aws/constructs" | ||
import { CachePolicy, CacheCookieBehavior } from "aws-cdk-lib/aws-cloudfront" | ||
|
||
export interface HelloCdkStackProps extends StackProps {} | ||
|
||
export class HelloCdkStack extends Stack { | ||
public constructor(scope: Construct, id: string, props: HelloCdkStackProps) { | ||
super(scope, id, props) | ||
|
||
const cachePolicy = new CachePolicy(this, "CachePolicy", { | ||
cookieBehavior: CacheCookieBehavior.all(), | ||
}) | ||
|
||
new AstroAWS(this, "AstroAWS", { | ||
cdk: { | ||
// This configures all subpaths of /api. | ||
apiBehavior: { | ||
cachePolicy, | ||
}, | ||
// This configures everything excluding subpaths of /api. | ||
cloudfrontDistribution: { | ||
cachePolicy, | ||
}, | ||
}, | ||
websiteDir: "../my-astro-project", | ||
}) | ||
} | ||
} | ||
``` | ||
|
||
``` | ||
``` |
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