ai generated solutions to our ai generated problems

This commit is contained in:
Heidi
2026-06-15 09:09:54 +01:00
parent 3eaf57912a
commit 9ad5cc0639
2 changed files with 2 additions and 38 deletions
+1
View File
@@ -1883,6 +1883,7 @@ function htmlWithSeo(req, data) {
const canonicalUrl = `${origin}${seo.path}`
return data.toString('utf8')
.replace(/\s+integrity=(["'])sha(?:256|384|512)-[^"']+\1/g, '')
.replaceAll('__PUBLIC_ORIGIN__', origin)
.replaceAll('__SEO_TITLE__', escapeHtml(seo.title))
.replaceAll('__SEO_DESCRIPTION__', escapeHtml(seo.description))
+1 -38
View File
@@ -1,4 +1,3 @@
import crypto from 'node:crypto'
import path from 'node:path'
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
@@ -36,42 +35,6 @@ function obfuscate() {
const MAX_TEAM_NAME_LENGTH = 80
function sri() {
return {
name: 'sri',
apply: 'build',
enforce: 'post',
transformIndexHtml: {
order: 'post',
handler(html, ctx) {
const bundle = ctx?.bundle
if (!bundle) return html
const hashFor = (fileName) => {
const asset = bundle[fileName]
if (!asset) return null
const source = asset.type === 'asset' ? asset.source : asset.code
const buf = Buffer.isBuffer(source) ? source : Buffer.from(source, 'utf8')
return `sha384-${crypto.createHash('sha384').update(buf).digest('base64')}`
}
const tagPattern = /<(?:script|link)\b[^>]*\b(?:src|href)=["'](\/[^"']+)["'][^>]*>/g
return html.replace(tagPattern, (tag, url) => {
if (/\bintegrity=/.test(tag)) return tag
const fileName = url.replace(/^\//, '').split('?')[0].split('#')[0]
const integrity = hashFor(fileName)
if (!integrity) return tag
const closing = tag.endsWith('/>') ? ' />' : '>'
const body = tag.slice(0, -closing.length)
let out = `${body} integrity="${integrity}"`
if (!/\bcrossorigin\b/.test(tag)) out += ' crossorigin="anonymous"'
return `${out}${closing}`
})
},
},
}
}
function isAllowedApiUrl(req) {
const url = new URL(req.url, 'http://localhost')
const params = url.searchParams
@@ -207,7 +170,7 @@ export default defineConfig(({ mode }) => {
return {
root: path.resolve(__dirname, 'frontend'),
publicDir: path.resolve(__dirname, 'frontend/public'),
plugins: [comingSoonDev(comingSoon), apiGuard(), react(), tailwindcss(), obfuscate(), sri()],
plugins: [comingSoonDev(comingSoon), apiGuard(), react(), tailwindcss(), obfuscate()],
build: {
outDir: path.resolve(__dirname, 'dist'),
emptyOutDir: true,