Skip to content
Snippets Groups Projects
Commit 88a06a2e authored by richard.petersen's avatar richard.petersen :sailboat:
Browse files

Only add css dependencies for files in the header

This prevents unnesessary large headers as the UI will filter for CSS files only
parent 483f364e
No related branches found
No related tags found
No related merge requests found
......@@ -58,6 +58,6 @@ describe('Responses contain custom headers', () => {
it('javascript file contains dependencies', async () => {
const response = await request(app).get('/index.html.js')
expect(response.statusCode).toBe(200)
expect(response.headers.dependencies).toEqual('example.js,main.css')
expect(response.headers.dependencies).toEqual('main.css')
})
})
......@@ -18,7 +18,7 @@ import promBundle from 'express-prom-bundle'
import swaggerUi from 'swagger-ui-express'
import yaml from 'js-yaml'
import fs from 'fs'
import { getDependencies, getOxManifests, getVersion } from './manifests.js'
import { getCSSDependenciesFor, getDependencies, getOxManifests, getVersion } from './manifests.js'
import { fileCache } from './files.js'
const ignorePaths = ['/ready', '/healthy']
......@@ -93,8 +93,7 @@ export function createApp () {
app.use(async (req, res, next) => {
const { 'content-type': contentType, content } = fileCache.get(req.path)
if (content) {
const allDependencies = await getDependencies()
const dependencies = allDependencies[req.path.substr(1)] || []
const dependencies = await getCSSDependenciesFor(req.path.substr(1))
return res
.setHeader('content-type', contentType)
.setHeader('dependencies', dependencies.join(','))
......@@ -107,8 +106,7 @@ export function createApp () {
try {
const { 'content-type': contentType, content } = await fileCache.fetchAndStore(req.path)
if (content) {
const allDependencies = await getDependencies()
const dependencies = allDependencies[req.path.substr(1)] || []
const dependencies = await getCSSDependenciesFor(req.path.substr(1))
return res
.setHeader('content-type', contentType)
.setHeader('dependencies', dependencies.join(','))
......
......@@ -106,6 +106,12 @@ export const getDependencies = (() => {
}
})()
export async function getCSSDependenciesFor (file) {
const allDependencies = await getDependencies()
const dependencies = allDependencies[file] || []
return dependencies.filter(dep => /\.css/i.test(dep))
}
export const getVersion = (() => {
let prevViteManifest
let version
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment