-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cdk-sanity-site): experimental release
- Loading branch information
1 parent
3718479
commit fa1f7e5
Showing
7 changed files
with
102 additions
and
0 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 @@ | ||
--- | ||
"@codedazur/cdk-sanity-site": minor | ||
--- | ||
|
||
Experimental release. |
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 @@ | ||
# Source Code | ||
src | ||
|
||
# Turbo Artifacts | ||
.turbo |
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,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2023 code d'azur Interactive B.V. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,11 @@ | ||
# SanitySite | ||
|
||
This construct is simply a [StaticSite](https://github.com/codedazur/toolkit/tree/main/packages/cdk-static-site#readme) with the addition of a CloudFront ViewerRequest Function to rewrite requests to the `index.html` file, since Sanity is compiled to a single route. | ||
|
||
```ts | ||
new SanitySite(this, "Sanity", { | ||
src: "../sanity/dist", | ||
}); | ||
``` | ||
|
||
For more information on usage and configuration, please refer to the `StaticSite` readme. |
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,38 @@ | ||
{ | ||
"name": "@codedazur/cdk-sanity-site", | ||
"version": "0.0.0", | ||
"main": ".dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" | ||
} | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"develop": "tsup src/index.ts --format esm,cjs --dts --watch", | ||
"build": "tsup src/index.ts --format esm,cjs --dts", | ||
"audit": "npm audit --omit dev", | ||
"lint": "TIMING=1 eslint \"**/*.ts*\"", | ||
"types": "tsc --noEmit", | ||
"test": "vitest run --passWithNoTests" | ||
}, | ||
"peerDependencies": { | ||
"aws-cdk-lib": ">=2", | ||
"constructs": ">=10" | ||
}, | ||
"dependencies": { | ||
"@codedazur/cdk-static-site": "^2.0.5" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.14.9", | ||
"aws-cdk-lib": "^2.147.2", | ||
"constructs": "^10.3.0", | ||
"esbuild": "^0.21.5" | ||
} | ||
} |
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,31 @@ | ||
import { StaticSite, StaticSiteProps } from "@codedazur/cdk-static-site"; | ||
import { FunctionCode } from "aws-cdk-lib/aws-cloudfront"; | ||
import { Construct } from "constructs"; | ||
|
||
export interface SanitySiteProps extends StaticSiteProps {} | ||
|
||
export class SanitySite extends StaticSite { | ||
constructor(scope: Construct, id: string, props: SanitySiteProps) { | ||
super(scope, id, { | ||
...props, | ||
distribution: { | ||
...props.distribution, | ||
functions: { | ||
...props.distribution?.functions, | ||
viewerRequest: [ | ||
...(props.distribution?.functions?.viewerRequest ?? []), | ||
FunctionCode.fromInline(/* js */ ` | ||
function rewriteToIndex(event, next) { | ||
if (!event.request.uri.match(/.*.[^?]*$/)) { | ||
event.request.uri = "/index.html"; | ||
} | ||
return next(event); | ||
} | ||
`), | ||
], | ||
}, | ||
}, | ||
}); | ||
} | ||
} |
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,3 @@ | ||
{ | ||
"extends": "@codedazur/tsconfig/cdk.json" | ||
} |