Skip to content

Commit

Permalink
feat(cdk-sanity-site): experimental release
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsdaniels committed Jul 14, 2024
1 parent 3718479 commit fa1f7e5
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-steaks-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codedazur/cdk-sanity-site": minor
---

Experimental release.
5 changes: 5 additions & 0 deletions packages/cdk-sanity-site/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Source Code
src

# Turbo Artifacts
.turbo
9 changes: 9 additions & 0 deletions packages/cdk-sanity-site/LICENSE.md
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.
11 changes: 11 additions & 0 deletions packages/cdk-sanity-site/README.md
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.
38 changes: 38 additions & 0 deletions packages/cdk-sanity-site/package.json
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"
}
}
31 changes: 31 additions & 0 deletions packages/cdk-sanity-site/src/constructs/SanitySite.ts
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);
}
`),
],
},
},
});
}
}
3 changes: 3 additions & 0 deletions packages/cdk-sanity-site/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@codedazur/tsconfig/cdk.json"
}

0 comments on commit fa1f7e5

Please sign in to comment.