Configure max-age header for frontend (#5775)
* upgrade scoutcamp * set max age for static content, add tests Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
@@ -146,6 +146,9 @@ const publicConfigSchema = Joi.object({
|
||||
rateLimit: Joi.boolean().required(),
|
||||
handleInternalErrors: Joi.boolean().required(),
|
||||
fetchLimit: Joi.string().regex(/^[0-9]+(b|kb|mb|gb|tb)$/i),
|
||||
documentRoot: Joi.string().default(
|
||||
path.resolve(__dirname, '..', '..', 'public')
|
||||
),
|
||||
requireCloudflare: Joi.boolean().required(),
|
||||
}).required()
|
||||
|
||||
@@ -437,10 +440,11 @@ class Server {
|
||||
log(`Server is starting up: ${this.baseUrl}`)
|
||||
|
||||
const camp = (this.camp = Camp.create({
|
||||
documentRoot: path.resolve(__dirname, '..', '..', 'public'),
|
||||
documentRoot: this.config.public.documentRoot,
|
||||
port,
|
||||
hostname,
|
||||
secure,
|
||||
staticMaxAge: 300,
|
||||
cert,
|
||||
key,
|
||||
}))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
const path = require('path')
|
||||
const { expect } = require('chai')
|
||||
const isSvg = require('is-svg')
|
||||
const config = require('config')
|
||||
@@ -13,7 +14,11 @@ describe('The server', function () {
|
||||
before('Start the server', async function () {
|
||||
// Fixes https://github.com/badges/shields/issues/2611
|
||||
this.timeout(10000)
|
||||
server = await createTestServer()
|
||||
server = await createTestServer({
|
||||
public: {
|
||||
documentRoot: path.resolve(__dirname, 'test-public'),
|
||||
},
|
||||
})
|
||||
baseUrl = server.baseUrl
|
||||
await server.start()
|
||||
})
|
||||
@@ -45,6 +50,16 @@ describe('The server', function () {
|
||||
.and.to.include('apple')
|
||||
})
|
||||
|
||||
it('should serve front-end with default maxAge', async function () {
|
||||
const { headers } = await got(`${baseUrl}/`)
|
||||
expect(headers['cache-control']).to.equal('max-age=300, s-maxage=300')
|
||||
})
|
||||
|
||||
it('should serve badges with custom maxAge', async function () {
|
||||
const { headers } = await got(`${baseUrl}npm/l/express`)
|
||||
expect(headers['cache-control']).to.equal('max-age=3600, s-maxage=3600')
|
||||
})
|
||||
|
||||
it('should redirect colorscheme PNG badges as configured', async function () {
|
||||
const { statusCode, headers } = await got(
|
||||
`${baseUrl}:fruit-apple-green.png`,
|
||||
|
||||
10
core/server/test-public/index.html
Normal file
10
core/server/test-public/index.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>shields.io</title>
|
||||
</head>
|
||||
<body>
|
||||
concise, consistent, legible
|
||||
</body>
|
||||
</html>
|
||||
6
package-lock.json
generated
6
package-lock.json
generated
@@ -7414,9 +7414,9 @@
|
||||
}
|
||||
},
|
||||
"@shields_io/camp": {
|
||||
"version": "18.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@shields_io/camp/-/camp-18.0.0.tgz",
|
||||
"integrity": "sha512-faQpvSVqqFX3LfRRdGQQHgXO1s2hsK+QWCZWXdM+3226fdikRCPT+O1YPyDMZdrG/vP5sL9PdOvajgGNwLlU6A==",
|
||||
"version": "18.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@shields_io/camp/-/camp-18.1.0.tgz",
|
||||
"integrity": "sha512-5YlcS1o1prpthiV+2hSI+SxO51e2zJ4Uc7dEh0qh2ST6NwiJM1lKhVQDKOQWqsR9dbtiDobOkCWyqTsDeVPK8w==",
|
||||
"requires": {
|
||||
"cookies": "~0.7.1",
|
||||
"fleau": "~16.2.0",
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@sentry/node": "^5.27.1",
|
||||
"@shields_io/camp": "^18.0.0",
|
||||
"@shields_io/camp": "^18.1.0",
|
||||
"badge-maker": "file:badge-maker",
|
||||
"bytes": "^3.1.0",
|
||||
"camelcase": "^6.2.0",
|
||||
|
||||
Reference in New Issue
Block a user