Skip to content

Commit d906aaa

Browse files
committed
chore: wip
chore: wip chore: wip
1 parent 9780a81 commit d906aaa

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

storage/framework/core/cloud/src/cloud/cdn.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,28 @@ export class CdnStack {
313313
const regexTrailingSlash = /.+\\/$/
314314
315315
exports.handler = (event, context, callback) => {
316-
console.log('event from stacks', event)
316+
const safeStringify = (obj, indent = 2) => {
317+
const cache = new Set()
318+
return JSON.stringify(obj, (key, value) => {
319+
if (typeof value === 'object' && value !== null) {
320+
if (cache.has(value)) return '[Circular]'
321+
cache.add(value)
322+
}
323+
return value
324+
}, indent)
325+
}
326+
console.log('Event from Stacks:', safeStringify(event))
317327
const request = event.Records[0].cf.request;
318-
let uri = request.uri;
319328
320-
if (uri === '/docs' || uri === '/docs/') {
321-
uri = '/index.html'
329+
if (request.uri === '/docs' || request.uri === '/docs/') {
330+
request.uri = '/docs/index.html'
331+
console.log('Request from Stacks:', safeStringify(request))
322332
callback(null, request)
323333
return
324334
}
325335
326336
// Append ".html" to origin request
337+
const uri = request.uri
327338
if (uri.match(regexSuffixless)) {
328339
request.uri = uri + config.suffix
329340
callback(null, request)
@@ -337,7 +348,6 @@ export class CdnStack {
337348
return
338349
}
339350
340-
request.uri = uri;
341351
callback(null, request);
342352
};
343353
`),

storage/framework/docs/.vitepress/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import { analyticsHead, faviconHead } from './head'
1616
export default withPwa(
1717
defineConfig({
1818
srcDir: p.projectPath('docs'),
19-
outDir: p.frameworkPath('docs/dist'),
19+
outDir: p.frameworkPath('docs/dist/docs'), // we need to currently ensure it outputs into docs/dist/docs to ensure the S3 storage key is correct for CloudFront origins
2020
cacheDir: p.frameworkPath('cache/docs'),
2121
assetsDir: '/assets',
22+
emptyOutDir: true,
2223

2324
// sitemap: {
2425
// hostname: 'stacks.localhost',

storage/framework/server/build.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,28 @@ async function main() {
137137
}
138138
}
139139

140-
// Process the storage folder and remove the .DS_Store files
141-
const glob4 = new Bun.Glob('**/*.DS_Store')
142-
const scanOptions4 = { cwd: path.storagePath(), onlyFiles: true }
143-
144-
for await (const file of glob4.scan(scanOptions4)) {
145-
fs.unlink(file)
140+
// next, lets move the dist/docs/index.html to dist/index.html
141+
const docsDistPath = path.frameworkPath('docs/dist')
142+
143+
log.info(`Moving dist/docs/index.html to dist/index.html`)
144+
try {
145+
await fs.rename(path.resolve(docsDistPath, 'docs/index.html'), path.resolve(docsDistPath, 'index.html'))
146+
log.success(`Moved dist/docs/index.html to dist/index.html`)
147+
} catch (error) {
148+
log.error(`Failed to move dist/docs/index.html`, error)
149+
process.exit(1)
146150
}
147151

152+
log.info(`Adjusting paths in index.html`)
153+
// now, let's adjust the paths in the index.html by simply updating all "/assets/ to "/dist/assets/
154+
let content = await fs.readFile(path.resolve(docsDistPath, 'index.html'), 'utf-8')
155+
156+
// Replace all instances of /assets/ with /dist/assets/
157+
content = content.replace(/\/assets\//g, '/dist/assets/')
158+
159+
await fs.writeFile(path.join(docsDistPath, 'index.html'), content, 'utf-8')
160+
log.success(`Adjusted paths in index.html`)
161+
148162
await outro({
149163
dir: import.meta.dir,
150164
startTime: perf,

0 commit comments

Comments
 (0)