Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for 404 page and response streaming #109

Merged
merged 8 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/gorgeous-bees-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@astro-aws/constructs": minor
"@astro-aws/adapter": minor
---

Added support for response streaming
6 changes: 6 additions & 0 deletions .changeset/serious-guests-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@astro-aws/constructs": minor
"@astro-aws/adapter": minor
---

Added support for 404 pages
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
rules: {
"import/no-useless-path-segments": "off",
"no-console": "off",
"no-warning-comments": "off",
},
settings: {
"import/parsers": {
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
matrix:
node_version:
- 18
- 20
cmd:
- build
- test
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nodejs 18.18.0
nodejs 18
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cSpell.words": ["astro", "awslambda", "streamify"],
"cSpell.words": ["astro", "awslambda", "powertools", "streamify"],
"files.associations": {
"*.mdx": "markdown"
},
Expand Down
10 changes: 5 additions & 5 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@
"start": "astro dev"
},
"dependencies": {
"@astrojs/starlight": "^0.11.0",
"astro": "^3.2.4",
"@astrojs/starlight": "^0.12.0",
"astro": "^3.5.5",
"sharp": "^0.32.6"
},
"devDependencies": {
"@astro-aws/adapter": "workspace:^",
"eslint": "^8.51.0",
"prettier": "^3.0.3",
"eslint": "^8.53.0",
"prettier": "^3.1.0",
"rimraf": "^5.0.5"
},
"engines": {
"node": "18.x"
"node": "18.x || 20.x"
}
}
9 changes: 0 additions & 9 deletions apps/infra/cdk.context.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
{
"acknowledged-issue-numbers": [8607],
"hosted-zone:account=357382603627:domainName=astro-aws.org:region=us-east-1": {
"Id": "/hostedzone/Z07804331OLCIOIZL4YQN",
"Name": "astro-aws.org."
},
"hosted-zone:account=738697399292:domainName=astro-aws.org:region=us-east-1": {
"Id": "/hostedzone/Z0584480MGUI8KRBPWM",
"Name": "astro-aws.org."
},
"hosted-zone:account=738697399292:domainName=astro-aws.org:region=us-east-2": {
"Id": "/hostedzone/Z0584480MGUI8KRBPWM",
"Name": "astro-aws.org."
}
}
2 changes: 1 addition & 1 deletion apps/infra/cdk.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"app": "node --enable-source-maps --es-module-specifier-resolution node dist/bin/infra.js",
"app": "node --enable-source-maps dist/bin/infra.js",
"context": {
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
Expand Down
12 changes: 6 additions & 6 deletions apps/infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@
"dependencies": {
"@astro-aws/constructs": "workspace:^",
"@astro-aws/docs": "workspace:^",
"aws-cdk": "^2.100.0",
"aws-cdk-lib": "^2.100.0",
"aws-cdk": "^2.109.0",
"aws-cdk-lib": "^2.109.0",
"constructs": "^10.3.0",
"eslint": "^8.51.0",
"prettier": "^3.0.3",
"eslint": "^8.53.0",
"prettier": "^3.1.0",
"typescript": "^5.2.2",
"workspace-tools": "^0.35.2"
"workspace-tools": "^0.36.3"
},
"devDependencies": {
"@astro-aws/scripts": "workspace:^",
"@types/node": "^18.18.0",
"eslint-config-get-off-my-lawn": "^7.2.0"
},
"engines": {
"node": "18.x"
"node": "18.x || 20.x"
},
"cli": {
"clean": [
Expand Down
88 changes: 45 additions & 43 deletions apps/infra/src/bin/infra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,64 @@ import {
Environments,
ENVIRONMENT_PROPS,
} from "../lib/constants/environments.js"
import { MonitoringStack } from "../lib/stacks/monitoring-stack.js"
import { WebsiteStack } from "../lib/stacks/website-stack.js"
import { RedirectStack } from "../lib/stacks/redirect-stack.js"
import type { CertificateStackProps } from "../lib/stacks/certificate-stack.js"
import { CertificateStack } from "../lib/stacks/certificate-stack.js"
import { GitHubOIDCStack } from "../lib/stacks/github-oidc-stack.js"
import { GitHubUsersStack } from "../lib/stacks/github-users-stack.js"

const app = new App()

const createStackName = (environment: string, stack: string) =>
`AstroAWS-${environment}-${stack}`
const createStackName = (
environment: string,
stack: string,
runtime?: string,
mode?: string,
) => ["AstroAWS", environment, stack, runtime, mode].filter(Boolean).join("-")

Object.entries(ENVIRONMENT_PROPS).forEach(([environment, environmentProps]) => {
const monitoringStack = new MonitoringStack(
app,
createStackName(environment, "Monitoring"),
environmentProps,
)
environmentProps.websites.forEach((websiteProps) => {
let certificateStack: CertificateStack | undefined

let certificateStack: CertificateStack | undefined
if (environment === Environments.DEV) {
// eslint-disable-next-line no-param-reassign
delete websiteProps.hostedZoneName
// eslint-disable-next-line no-param-reassign
delete websiteProps.aliases
}

if (websiteProps.hostedZoneName && websiteProps.aliases) {
certificateStack = new CertificateStack(
app,
createStackName(
environment,
"Certificate",
websiteProps.runtime,
websiteProps.mode,
),
{
...environmentProps,
aliases: websiteProps.aliases,
hostedZoneName: websiteProps.hostedZoneName,
},
)
}

if (environmentProps.hostedZoneName) {
certificateStack = new CertificateStack(
new WebsiteStack(
app,
createStackName(environment, "Certificate"),
environmentProps as CertificateStackProps,
createStackName(
environment,
"Website",
websiteProps.runtime,
websiteProps.mode,
),
{
...environmentProps,
...websiteProps,
certificate: certificateStack?.certificate,
hostedZone: certificateStack?.hostedZone,
},
)
}
})

if (environment === Environments.DEV) {
new GitHubUsersStack(
Expand All @@ -48,33 +77,6 @@ Object.entries(ENVIRONMENT_PROPS).forEach(([environment, environmentProps]) => {
)
}

new WebsiteStack(app, createStackName(environment, "Website"), {
...environmentProps,
certificate: certificateStack?.certificate,
cloudwatchDashboard: monitoringStack.cloudwatchDashboard,
hostedZone: certificateStack?.hostedZone,
})

if (environment === Environments.PROD && environmentProps.hostedZoneName) {
const redirectProps = {
...environmentProps,
alias: ["www", environmentProps.alias].filter(Boolean).join("."),
}

const redirectCertificateStack = new CertificateStack(
app,
createStackName(environment, "RedirectCertificate"),
redirectProps as CertificateStackProps,
)

new RedirectStack(app, createStackName(environment, "Redirect"), {
...redirectProps,
certificate: redirectCertificateStack.certificate,
cloudwatchDashboard: monitoringStack.cloudwatchDashboard,
hostedZone: redirectCertificateStack.hostedZone,
})
}

Tags.of(app).add("Project", "AstroAWS")
Tags.of(app).add("Environment", environment)
})
127 changes: 89 additions & 38 deletions apps/infra/src/lib/constants/environments.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { env } from "node:process"

import type { AstroAWSStackProps } from "../types/astro-aws-stack-props.js"
import { type StaticWebsiteStackProps } from "../stacks/website-stack.js"

const base = {
analyticsReporting: false,
Expand All @@ -14,61 +15,111 @@ const base = {

const Environments = {
DEV: "DEV",
EDGE: "EDGE",
PERSONAL: "PERSONAL",
PROD: "PROD",
SSR: "SSR",
STREAM: "STREAM",
} as const

type Environment = (typeof Environments)[keyof typeof Environments]

const ENVIRONMENT_PROPS: Record<Environment, AstroAWSStackProps> = {
type EnvironmentProps = Readonly<
AstroAWSStackProps & {
websites: readonly (Partial<AstroAWSStackProps> & StaticWebsiteStackProps)[]
}
>

const ENVIRONMENT_PROPS: Record<Environment, EnvironmentProps> = {
[Environments.DEV]: {
...base,
alias: "static.dev",
environment: Environments.DEV,
hostedZoneName: "astro-aws.org",
package: "@astro-aws/docs",
},
[Environments.EDGE]: {
...base,
alias: "edge.dev",
distDir: "dist/edge",
env: {
...base.env,
region: "us-east-1",
},
environment: Environments.EDGE,
hostedZoneName: "astro-aws.org",
package: "@astro-aws/examples-base",
websites: [
{
aliases: ["www.static.dev", "static.dev"],
hostedZoneName: "astro-aws.org",
mode: "static",
package: "@astro-aws/docs",
runtime: "nodejs20",
},
{
aliases: ["www.ssr.nodejs18.dev", "ssr.nodejs18.dev"],
hostedZoneName: "astro-aws.org",
mode: "ssr",
package: "@astro-aws/examples-base",
runtime: "nodejs18",
},
{
aliases: ["www.stream.nodejs18.dev", "stream.nodejs18.dev"],
hostedZoneName: "astro-aws.org",
mode: "ssr-stream",
package: "@astro-aws/examples-base",
runtime: "nodejs18",
},
{
aliases: ["www.edge.nodejs18.dev", "edge.nodejs18.dev"],
env: {
...base.env,
region: "us-east-1",
},
hostedZoneName: "astro-aws.org",
mode: "edge",
package: "@astro-aws/examples-base",
runtime: "nodejs18",
},
{
aliases: ["www.ssr.nodejs20.dev", "ssr.nodejs20.dev"],
hostedZoneName: "astro-aws.org",
mode: "ssr",
package: "@astro-aws/examples-base",
runtime: "nodejs20",
},
{
aliases: ["www.stream.nodejs20.dev", "stream.nodejs20.dev"],
hostedZoneName: "astro-aws.org",
mode: "ssr-stream",
package: "@astro-aws/examples-base",
runtime: "nodejs20",
},
{
aliases: ["www.edge.nodejs20.dev", "edge.nodejs20.dev"],
env: {
...base.env,
region: "us-east-1",
},
hostedZoneName: "astro-aws.org",
mode: "edge",
package: "@astro-aws/examples-base",
runtime: "nodejs20",
},
],
},
[Environments.PROD]: {
...base,
environment: Environments.PROD,
hostedZoneName: "astro-aws.org",
package: "@astro-aws/docs",
websites: [
{
aliases: ["www", "*"],
hostedZoneName: "astro-aws.org",
mode: "static",
package: "@astro-aws/docs",
},
],
},
[Environments.PERSONAL]: {
...base,
environment: Environments.PERSONAL,
package: "@astro-aws/docs",
},
[Environments.SSR]: {
...base,
alias: "ssr.dev",
distDir: "dist/ssr",
environment: Environments.SSR,
hostedZoneName: "astro-aws.org",
package: "@astro-aws/examples-base",
},
[Environments.STREAM]: {
...base,
alias: "stream.dev",
distDir: "dist/ssr-stream",
environment: Environments.STREAM,
hostedZoneName: "astro-aws.org",
package: "@astro-aws/examples-base",
websites: [
{
mode: "static",
package: "@astro-aws/docs",
},
{
mode: "ssr",
package: "@astro-aws/examples-base",
},
{
mode: "ssr-stream",
package: "@astro-aws/examples-base",
},
],
},
} as const

Expand Down
Loading
Loading