Ryan
06/19/2021, 8:08 AMStaticSite
construct. It's a great and welcome additional, but it seems like there are quite a few adjacent problems that need solving that could be nicely wrapped up in it. (Only solutions I've come up with feel really hacky and are cumbersome)
More control over the deployment to the s3 bucket
• Setting metadata on files
• Not deleting old files, but rather setting an expiry on them to be removed after a period (eg. so users that are running the existing frontend don't suddenly get 404's. Frontend frameworks usually used content hashed file named to handle versioning and caching)
Setting environment variables for the frontend
• Ideally done at deployment time as to not require a frontend rebuild
• Also, would be great to be able to include Cloudformation outputs, which would also need to happen after it's been built
• Something generic, like a find/replace with a file glob would be great and flexible. This it could happen in a json file, in compiled code, in index.html, etc.
That's about it for my wish list 🙂
Thinking this would require a whole new custom resource right?Frank
Frank
Not deleting old files, but rather setting an expiry on them to be removed after a periodYour point on users getting 404s makes sense. But what about the scenario where I renamed
about.html
to aboutus.html
, and we don’t want users to hit the about.html
page. (cc @Dan Van Brunt)Frank
Ryan
06/20/2021, 5:18 AMRyan
06/20/2021, 5:21 AMJay
Frank
Setting metadata on filesYou can configure different
cacheControl
settings to different files. For example, don’t cache *.html
and cache *.css *.js
forever. Example here - https://docs.serverless-stack.com/constructs/StaticSite#configure-caching
Not deleting old files, but rather setting an expiry on them to be removed after a period
StaticSite
now does atomic deploys. Each deployment gets deployed to a new folder in S3 bucket.
Setting environment variables for the frontendYou can specify a list of glob patterns, with the search and replace terms for each. Example here - https://docs.serverless-stack.com/constructs/StaticSite#replace-deployed-values
Frank
Ryan
06/21/2021, 9:38 AMRyan
06/21/2021, 4:22 PMreplaceValues
But I'm getting an error
Error: Received response status [FAILED] from custom resource. Message returned: An error occurred (AccessDenied) when calling the ListObjects operation: Access Denied
I tried removing and creating the entire stack again, but still the same Error. I can investigate more a bit later.
Entire config is:
const frontend = new sst.StaticSite(this, "StaticSite", {
path: '../../frontend',
buildCommand: 'npm run build:prod',
buildOutput: 'dist/',
customDomain: {
hostedZone: process.env.HOSTED_ZONE,
domainName: process.env.DOMAIN
},
replaceValues: [
{
files: '*.json',
search: '${API_URL}',
replace: api.customDomainUrl
}
]
});
Frank
Frank
Frank
Ryan
06/22/2021, 3:42 AMRyan
06/22/2021, 3:43 AMsst remove
?Frank
sst remove
.Ryan
06/22/2021, 3:49 AM> npx sst remove frontend
Preparing your SST app
Detected tsconfig.json
Transpiling source
Linting source
Running type checker
Removing dev-project-frontend
Building Lambda function src/lambda.handler
> project@0.0.0 build:prod
> ng build --configuration=production
- Generating browser application bundles...
Frank
Frank
Frank
Ryan
06/22/2021, 5:12 AM