Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
chore: wip

chore: wip
  • Loading branch information
chrisbbreuer committed Sep 18, 2024
1 parent 29f2423 commit 87ef4ba
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion storage/framework/.biomelintrc-auto-import.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,4 @@
"whenever"
]
}
}
}
18 changes: 12 additions & 6 deletions storage/framework/core/cloud/src/cloud/cdn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,15 @@ export class CdnStack {
protocolPolicy: cloudfront.OriginProtocolPolicy.HTTPS_ONLY,
})

const apiCachePolicy = this.setApiCachePolicy(scope)

return {
'/api': {
origin,
compress: true,
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD_OPTIONS,
cachePolicy: this.setApiCachePolicy(scope),
cachePolicy: apiCachePolicy,
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
realtimeLogConfig: this.realtimeLogConfig,
},
Expand All @@ -276,7 +278,7 @@ export class CdnStack {
compress: true,
allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD_OPTIONS,
cachePolicy: this.apiCachePolicy,
cachePolicy: apiCachePolicy,
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
realtimeLogConfig: this.realtimeLogConfig,
},
Expand Down Expand Up @@ -514,7 +516,10 @@ export class CdnStack {
]
keysToRemove.forEach((key) => delete env[key as EnvKey])

behaviorOptions = this.apiBehaviorOptions(scope, props)
behaviorOptions = {
...this.apiBehaviorOptions(scope, props),
...behaviorOptions,
}
}

// if docMode is used, we don't need to add a behavior for the docs
Expand Down Expand Up @@ -549,15 +554,16 @@ export class CdnStack {

this.apiCachePolicy = new cloudfront.CachePolicy(scope, 'ApiCachePolicy', {
comment: 'Stacks API Cache Policy',
cachePolicyName: `${this.props.slug}-${this.props.appEnv}-api-cache-policy`,
cachePolicyName: `${this.props.slug}-${this.props.appEnv}-api-cache-policy-${this.props.timestamp}`,
defaultTtl: Duration.seconds(0),
minTtl: Duration.seconds(0),
maxTtl: Duration.seconds(0),
maxTtl: Duration.seconds(1), // Changed from 0 to 1 second

// minTtl: config.cloud.cdn?.minTtl ? Duration.seconds(config.cloud.cdn.minTtl) : undefined,
cookieBehavior: cloudfront.CacheCookieBehavior.all(),
headerBehavior: cloudfront.CacheHeaderBehavior.allowList('Authorization', 'Content-Type'),
queryStringBehavior: cloudfront.CacheQueryStringBehavior.all(),
enableAcceptEncodingGzip: true, // Added this line
enableAcceptEncodingBrotli: true, // Added this line
})

return this.apiCachePolicy
Expand Down
2 changes: 1 addition & 1 deletion storage/framework/core/vite-plugin/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function router(options?: RouterOptions) {

if (options?.type === 'views') {
return VueRouter({
exclude: ['/dashboard/**', '/errors/**', '/system-tray/**'],
exclude: ['/dashboard/**', '/errors/**', '/system-tray/**', '/docs/**', '/api/**'], // these are provided by the framework, and that's why they cannot be reused
...opts,
})
}
Expand Down
2 changes: 1 addition & 1 deletion storage/framework/server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ cdk.out
chunk-*
*.node
index.js*
storage-tmp
storage

2 changes: 1 addition & 1 deletion storage/framework/server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ COPY --from=builder /usr/src/tsconfig.json ./tsconfig.json
USER root
RUN mkdir -p ./storage

COPY --chown=bun:bun ./storage-tmp ./storage
COPY --chown=bun:bun ./storage ./storage

# Add storage volume for logs and other files
VOLUME ["/usr/src/storage"]
Expand Down
18 changes: 9 additions & 9 deletions storage/framework/server/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function main() {
log.info('Stopped stacks-server container')
}

log.info('Deleting old files...')
log.info('Cleanup of previous build files...')
log.info(` ${path.userServerPath('app')}`, { styled: false })
await deleteFolder(path.userServerPath('app'))
log.info(` ${path.userServerPath('config')}`, { styled: false })
Expand All @@ -33,8 +33,9 @@ async function main() {
log.info(` ${path.userServerPath('docs')}`, { styled: false })
await deleteFolder(path.userServerPath('docs'))
log.info(` ${path.userServerPath('storage')}`, { styled: false })
await deleteFolder(path.userServerPath('storage'))
log.success('Deleted old files')
// await deleteFolder(path.userServerPath('storage'))
await Bun.$`rm -rf ${path.userServerPath('storage')}`.text()
log.success('Cleaned up previous build files')

log.info('Building...')
const result = await build({
Expand All @@ -49,7 +50,7 @@ async function main() {
if (result.success) {
log.success('Server built')
} else {
log.error('Build failed')
log.error('Server Build failed')
process.exit(1)
}

Expand Down Expand Up @@ -130,13 +131,13 @@ async function main() {

try {
Bun.$.cwd(path.userServerPath())
await Bun.$`rm -rf ./storage-tmp/framework/**/dist ./storage-tmp/**/node_modules ./storage-tmp/framework/**/src ./storage-tmp/framework/core/**/tests ./storage-tmp/**/*.DS_Store ./storage-tmp/**/*.lockb`.text()
await Bun.$`rm -rf ./storage/framework/**/dist ./storage/**/node_modules ./storage/framework/**/src ./storage/framework/core/**/tests ./storage/**/*.DS_Store ./storage/**/*.lockb`
.nothrow()
.text()
log.success('Optimized Docker Image size')
} catch (err: any) {
log.error('Optimization failed')
console.log(`Failed with code ${err.exitCode}`)
console.log(err.stdout.toString())
console.log(err.stderr.toString())
log.error(err)
process.exit(1)
}

Expand All @@ -148,7 +149,6 @@ async function main() {
})

if (cloud.api?.deploy) await buildDockerImage()
await Bun.$`rm -rf ${path.userServerPath('storage-tmp')}`.text()
}

main()
Expand Down
4 changes: 2 additions & 2 deletions storage/framework/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"contributors": ["Chris Breuer <[email protected]>"],
"files": ["README.md", "dist", "src"],
"scripts": {
"dev": "./dev local",
"dev:cloud": "docker run -d -p 3000:3000 --name stacks-server --restart unless-stopped stacks",
"dev": "docker run -d -p 3000:3000 --name stacks-server --restart unless-stopped stacks",
"dev:local": "./dev local",
"build": "bun build.ts"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion storage/framework/server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export async function buildDockerImage() {
log.success('Copied docs files')

log.info('Copying storage files...')
await cleanCopy(projectPath('storage'), frameworkPath('server/storage-tmp'))
await cleanCopy(projectPath('storage'), frameworkPath('server/storage'))
log.success('Copied storage files')

log.info('Copying .env file...')
Expand Down

0 comments on commit 87ef4ba

Please sign in to comment.