ai generated solutions to our ai generated problems
This commit is contained in:
@@ -1883,6 +1883,7 @@ function htmlWithSeo(req, data) {
|
|||||||
const canonicalUrl = `${origin}${seo.path}`
|
const canonicalUrl = `${origin}${seo.path}`
|
||||||
|
|
||||||
return data.toString('utf8')
|
return data.toString('utf8')
|
||||||
|
.replace(/\s+integrity=(["'])sha(?:256|384|512)-[^"']+\1/g, '')
|
||||||
.replaceAll('__PUBLIC_ORIGIN__', origin)
|
.replaceAll('__PUBLIC_ORIGIN__', origin)
|
||||||
.replaceAll('__SEO_TITLE__', escapeHtml(seo.title))
|
.replaceAll('__SEO_TITLE__', escapeHtml(seo.title))
|
||||||
.replaceAll('__SEO_DESCRIPTION__', escapeHtml(seo.description))
|
.replaceAll('__SEO_DESCRIPTION__', escapeHtml(seo.description))
|
||||||
|
|||||||
+1
-38
@@ -1,4 +1,3 @@
|
|||||||
import crypto from 'node:crypto'
|
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
import { defineConfig, loadEnv } from 'vite'
|
import { defineConfig, loadEnv } from 'vite'
|
||||||
import react from '@vitejs/plugin-react'
|
import react from '@vitejs/plugin-react'
|
||||||
@@ -36,42 +35,6 @@ function obfuscate() {
|
|||||||
|
|
||||||
const MAX_TEAM_NAME_LENGTH = 80
|
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) {
|
function isAllowedApiUrl(req) {
|
||||||
const url = new URL(req.url, 'http://localhost')
|
const url = new URL(req.url, 'http://localhost')
|
||||||
const params = url.searchParams
|
const params = url.searchParams
|
||||||
@@ -207,7 +170,7 @@ export default defineConfig(({ mode }) => {
|
|||||||
return {
|
return {
|
||||||
root: path.resolve(__dirname, 'frontend'),
|
root: path.resolve(__dirname, 'frontend'),
|
||||||
publicDir: path.resolve(__dirname, 'frontend/public'),
|
publicDir: path.resolve(__dirname, 'frontend/public'),
|
||||||
plugins: [comingSoonDev(comingSoon), apiGuard(), react(), tailwindcss(), obfuscate(), sri()],
|
plugins: [comingSoonDev(comingSoon), apiGuard(), react(), tailwindcss(), obfuscate()],
|
||||||
build: {
|
build: {
|
||||||
outDir: path.resolve(__dirname, 'dist'),
|
outDir: path.resolve(__dirname, 'dist'),
|
||||||
emptyOutDir: true,
|
emptyOutDir: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user