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

add: OXUI-1092 - Add configurable salt to manually invalidate client caches

parent 88f4c8bf
No related branches found
No related tags found
No related merge requests found
......@@ -75,6 +75,16 @@ It is possible to horizontally scale the UI Middleware, as more clients are fetc
| `compressFileSize` | Larger files will be gzipped | `600` |
| `compressFileTypes` | Set of compression mime types |see values|
**config map**
```yaml
# List of urls where to find ui containers
baseUrls:
- http://service.namespace.svc.cluster.local/
# optional, when this number is changed, the changes on clients will be invalidated and will reload the ui-sources
salt: '1234'
```
## Ingress
When using Ingress to make the service available to the public, the service is intended to be
......
import request from 'supertest'
import { brotliParser, generateSimpleViteManifest, mockApp, mockConfig, mockFetch, mockRedis } from './util.js'
import { expect } from 'chai'
import * as td from 'testdouble'
import RedisMock from 'ioredis-mock'
describe('Salt', function () {
let app
let config
beforeEach(async function () {
mockConfig(config = { baseUrls: ['http://ui-server/'] })
mockRedis()
mockFetch({
'http://ui-server': {
'/manifest.json': generateSimpleViteManifest({ 'example.js': 'test' }),
'/example.js': ''
}
})
app = await mockApp()
})
afterEach(async function () {
td.reset()
await new RedisMock().flushdb()
})
it('change version when salt changes', async function () {
const response = await request(app.server).get('/manifests').parse(brotliParser)
expect(response.statusCode).to.equal(200)
expect(response.headers.version).to.equal('1916675216')
// update salt
config.salt = '1'
await import('../src/version.js').then(async ({ updateVersionProcessor }) => {
// need to process two times to actually trigger the update
await updateVersionProcessor()
await updateVersionProcessor()
})
const responseAfterUpdate = await request(app.server).get('/manifests').parse(brotliParser)
expect(responseAfterUpdate.statusCode).to.equal(200)
expect(responseAfterUpdate.headers.version).to.equal('1916675216-1')
})
})
......@@ -7,12 +7,18 @@ class Config {
const doc = yaml.load(await fs.readFile('./config/config.yaml', 'utf8'))
// @ts-ignore
this._urls = doc.baseUrls
// @ts-ignore
this._salt = doc.salt
logger.debug('[Config] Config has been loaded')
}
get urls () {
return this._urls || []
}
get salt () {
return this._salt
}
}
export const configMap = new Config()
......@@ -45,7 +45,7 @@ export const fetchLatestVersion = async () => {
logger.error(`[Version] Cannot fetch manifest from ${baseUrl}. Version info will not be correct.`)
}
}))
return hash(infos)
return `${hash(infos)}${configMap.salt ? `-${configMap.salt}` : ''}`
}
export async function getLatestVersion () {
......
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