Yousef
09/23/2021, 2:39 AMpreview
cookie and bypassing the CDN and regenerate the page @ edge.Yousef
09/23/2021, 2:40 AMYousef
09/23/2021, 2:41 AMhttps://<your-site>/api/preview?secret=<token>&slug=<path>
Yousef
09/23/2021, 2:47 AMFrank
lambda-at-edge
package - https://github.com/serverless-nextjs/serverless-next.js/pull/562Frank
Yousef
09/23/2021, 2:51 AMYousef
09/23/2021, 2:52 AMFrank
NextjsSite
uses a forked version of lambda-at-edge
and pins it at v3.3.0.Frank
Yousef
09/23/2021, 2:57 AMYousef
09/23/2021, 2:59 AMFrank
Yousef
09/23/2021, 3:07 AMYousef
09/23/2021, 3:07 AMYousef
09/23/2021, 3:07 AMYousef
09/23/2021, 3:07 AMFrank
Yousef
09/23/2021, 3:08 AMFrank
Frank
Yousef
09/23/2021, 3:09 AMFrank
Yousef
09/23/2021, 3:10 AMYousef
09/23/2021, 3:11 AMYousef
09/23/2021, 3:11 AMFrank
Yousef
09/23/2021, 3:14 AMYousef
09/23/2021, 3:14 AMYousef
09/23/2021, 3:14 AMFrank
Yousef
09/23/2021, 3:16 AMFrank
Yousef
09/23/2021, 3:16 AMFrank
Yousef
09/23/2021, 3:19 AMFrank
serverless.yml
in your project with content:
myNextApplication:
component: "@sls-next/serverless-component@3.4.0-alpha.9"
2. npm/yarn install -g serverless (or install locally)
3. run serverless
Yousef
09/23/2021, 3:20 AMFrank
Frank
serverless remove
and remove serverless.yml
to clean everything up afterwards.Frank
Yousef
09/23/2021, 3:24 AMFrank
Frank
Yousef
09/23/2021, 3:44 AMYousef
09/23/2021, 3:45 AMYousef
09/23/2021, 3:45 AMYousef
09/23/2021, 3:48 AMYousef
09/23/2021, 3:52 AMFrank
Frank
Frank
IsPreview: false
Frank
Frank
/preview
Yousef
09/23/2021, 4:35 AMFrank
IsPreview: true
Frank
/api/preview
export default function handler(req, res) {
res.setPreviewData({})
res.redirect('/preview')
}
Frank
/preview
export async function getStaticProps(context) {
return {
props: {
isPreview: context.preview ? "true" : "false",
}
}
}
export default function Post({ isPreview, envUrl }) {
return (
<h1>Is Preview: {isPreview}</h1>
)
}
Frank
Frank
Yousef
09/23/2021, 4:47 AMYousef
09/23/2021, 4:49 AMYousef
09/23/2021, 4:50 AMYousef
09/23/2021, 4:50 AMexport async function getStaticPaths({ locales }: GetStaticPathsContext) {
const allPages = await getAllPagesWithSlug()
return {
paths: [], // getLocalePaths(allPages, locales),
fallback: 'blocking',
}
}
Yousef
09/23/2021, 4:51 AMYousef
09/23/2021, 4:52 AMYousef
09/23/2021, 4:55 AMFrank
Frank
Frank
/api/preview
looks like this now (takes a slug query string and redirects to it)
export default function handler(req, res) {
res.setPreviewData({})
res.redirect(req.query.slug)
}
Frank
/ssg-preview/[id]
looks like this now (2 pages, /ssg-preview/hello
and /ssg-preview/world
)
export async function getStaticProps(context) {
return {
props: {
title: context.params.id,
isPreview: context.preview ? "true" : "false",
}
}
}
export async function getStaticPaths() {
return {
paths: [
{
params: {
id: "hello"
}
},
{
params: {
id: "world"
}
}
],
fallback: false
}
}
export default function Post({ title, isPreview }) {
return (
<div>
<h1>Title: {title}</h1>
<h1>IsPreview: {isPreview}</h1>
</div>
)
}
Yousef
09/23/2021, 5:11 AMYousef
09/23/2021, 5:11 AMFrank
Yousef
09/23/2021, 5:16 AMFrank
Frank
false
https://dd15x82s18vvm.cloudfront.net/ssg-preview/helloFrank
Frank
true
Frank
/[id]
page and the preview api route. And instead of hitting contentful for content, put in some dummy content inline. Strip it to the minimal and see if the issue still persist?Yousef
09/23/2021, 5:33 AMFrank
Yousef
09/23/2021, 7:39 PMYousef
09/23/2021, 7:39 PMYousef
09/23/2021, 7:39 PMFrank
Yousef
09/23/2021, 7:48 PMYousef
09/23/2021, 7:48 PMYousef
09/23/2021, 7:49 PMFrank
Yousef
09/23/2021, 7:51 PMYousef
09/23/2021, 7:51 PM/en-GB//* -> /en-GB/*
Frank
Yousef
09/23/2021, 7:56 PMYousef
09/23/2021, 7:57 PMYousef
09/23/2021, 7:58 PMYousef
09/23/2021, 7:58 PMYousef
09/23/2021, 7:59 PMYousef
09/23/2021, 8:33 PMFrank
Yousef
09/23/2021, 9:37 PMYousef
09/23/2021, 9:37 PMResource handler returned message: "Invalid request provided: The specified SSL certificate doesn't exist, isn't in us-east-1 region, isn't valid, or doesn't include a valid certificate chain. (Service: CloudFront, Status Code: 400, Request ID: e4799a06-2d30-47de-9473-44e41e092cdc, Extended Request ID: null)" (RequestToken: b9b46af0-6649-563d-7cce-6eb87bf19b41, HandlerErrorCode: InvalidRequest)
Frank
NextjsSite
?Yousef
09/23/2021, 10:01 PMimport * as sst from '@serverless-stack/resources';
export default class MyStack extends sst.Stack {
constructor(scope: any, id: string, props: any) {
super(scope, id, props);
const site = new sst.NextjsSite(this, 'NextSite', {
path: './',
customDomain: {
domainName:
scope.stage === "prod" ? "<http://hautehijab.com|hautehijab.com>" : `${scope.stage}.<http://hautehijab.com|hautehijab.com>`,
domainAlias: scope.stage === "prod" ? "<http://www.hautehijab.com|www.hautehijab.com>" : undefined,
hostedZone: "<http://hautehijab.com|hautehijab.com>",
}
});
this.addOutputs({
URL: site.url,
});
}
}
Yousef
09/23/2021, 10:01 PMYousef
09/23/2021, 10:01 PMYousef
09/23/2021, 10:01 PMYousef
09/23/2021, 10:01 PMimport * as sst from '@serverless-stack/resources';
export default class MyStack extends sst.Stack {
constructor(scope: any, id: string, props: any) {
super(scope, id, props);
const site = new sst.NextjsSite(this, 'NextSite', {
path: './',
customDomain: {
domainName:
scope.stage === "prod" ? "<http://www.hautehijab.com|www.hautehijab.com>" : `${scope.stage}.<http://hautehijab.com|hautehijab.com>`,
domainAlias: scope.stage === "prod" ? "<http://hautehijab.com|hautehijab.com>" : undefined,
hostedZone: "<http://hautehijab.com|hautehijab.com>",
}
});
this.addOutputs({
URL: site.url,
});
}
}
Yousef
09/23/2021, 10:02 PMYousef
09/23/2021, 10:02 PMYousef
09/23/2021, 10:41 PMYousef
09/23/2021, 10:42 PMYousef
09/23/2021, 10:45 PMYousef
09/23/2021, 10:59 PMFrank
Yousef
09/24/2021, 1:07 AMYousef
09/24/2021, 1:07 AMconst site = new sst.NextjsSite(this, 'NextSite', {
path: './',
customDomain: {
domainName:
scope.stage === "production" ? "<http://www.hautehijab.com|www.hautehijab.com>" : `${scope.stage}.<http://hautehijab.com|hautehijab.com>`,
domainAlias: scope.stage === "production" ? "<http://hautehijab.com|hautehijab.com>" : undefined,
hostedZone: "<http://hautehijab.com|hautehijab.com>",
}
});
Yousef
09/24/2021, 1:07 AMwww
as the default domain and naked domain as the aliasYousef
09/24/2021, 1:07 AMYousef
09/24/2021, 1:08 AMFrank