Skip to content

Instantly share code, notes, and snippets.

@sammyjoyce
Created December 1, 2023 02:43
Show Gist options
  • Select an option

  • Save sammyjoyce/1d08bf905b7693c2a461194197e75c04 to your computer and use it in GitHub Desktop.

Select an option

Save sammyjoyce/1d08bf905b7693c2a461194197e75c04 to your computer and use it in GitHub Desktop.
SST v2 example: NextjsSite with custom domain and storage bindings
import { NextjsSite, StackContext, use } from "sst/constructs";
import { DNS } from "./dns";
import { Storage } from "./storage";
import { Auth } from "./auth";
import { API } from "./api";
export function Site({ stack, app }: StackContext) {
const dns = use(DNS);
const api = use(API);
const auth = use(Auth);
const storage = use(Storage);
const site = new NextjsSite(stack, "Site", {
path: "packages/frontend",
bind: [storage.bucket],
timeout: "20 seconds",
imageOptimization: {
memorySize: "2048 MB",
},
experimental: {
streaming: true,
},
environment: {
REGION: stack.region,
NEXT_PUBLIC_AUTH_URL: auth.url,
NEXT_PUBLIC_BUCKET_NAME: storage.bucket.bucketName,
S3_UPLOAD_BUCKET: storage.bucket.bucketName,
S3_UPLOAD_REGION: stack.region,
NEXT_PUBLIC_API_URL: api.customDomainUrl || api.url,
SITE_URL:
app.mode === "dev" ? "http://localhost:3000" : "https://" + dns.domain,
NEXT_PUBLIC_CDN_URL: storage.cdn,
},
customDomain: {
domainName: dns.domain,
hostedZone: dns.zone.zoneName,
domainAlias: app.mode === "dev" ? undefined : `www.${dns.domain}`,
},
});
stack.addOutputs({
SiteURL: site.customDomainUrl || site.url,
SiteDistributionId: site.cdk?.distribution.distributionId,
});
return site;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment