ai generated solutions to our ai generated problems
This commit is contained in:
+1
-38
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user