Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/api/__tests__/safety.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ it('e2e tests are only in test/e2e or test/visual', () => {
}
})

// In production, Nexus only serves /assets/* and /index.html — files at other
// paths under public/ would work in Vite dev but 404 in production.
// https://github.com/oxidecomputer/omicron/blob/b2b1e39/nexus/src/external_api/console_api.rs#L409-L439
it('public/ only contains assets/', () => {
const entries = fs.readdirSync(path.resolve(__dirname, '../../../public'))
expect(entries).toMatchInlineSnapshot(`
[
"assets",
]
`)
})

// 8-4-4-4-12 hex digits
const UUID_RE = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'

Expand Down
File renamed without changes.
16 changes: 8 additions & 8 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,21 @@ export default defineConfig(({ mode }) => ({
},
{
// Inject theme-init.js as a classic (non-module) render-blocking script
// so it sets data-theme before first paint. It lives in public/ so it
// passes CSP default-src 'self'. We inject it here rather than putting
// it in index.html because Vite tries to bundle any <script src> it finds
// there. Content hash query param handles cache-busting since public/
// files aren't fingerprinted by Vite. We cache static assets for a year,
// so we need the hash.
// so it sets data-theme before first paint. It lives in public/assets/
// so it passes CSP default-src 'self' and is served by the /assets/*
// route in Nexus. We inject it here rather than putting it in index.html
// because Vite tries to bundle any <script src> it finds there. Content
// hash query param handles cache-busting since public/ files aren't
// fingerprinted by Vite.
name: 'theme-init',
transformIndexHtml() {
const content = readFileSync(resolve(__dirname, 'public/theme-init.js'))
const content = readFileSync(resolve(__dirname, 'public/assets/theme-init.js'))
const hash = createHash('sha256').update(content).digest('hex').slice(0, 8)
return [
{
injectTo: 'head-prepend',
tag: 'script',
attrs: { src: `/theme-init.js?v=${hash}` },
attrs: { src: `/assets/theme-init.js?v=${hash}` },
},
]
},
Expand Down
Loading