server/client: tidy up cache control, enforce server validation and remove version from build assets file names
This commit is contained in:
parent
71293de694
commit
92ef3b7ac1
9 changed files with 51 additions and 24 deletions
|
|
@ -2,7 +2,7 @@
|
|||
"name": "open-stage-control",
|
||||
"productName": "Open Stage Control",
|
||||
"description": "Libre and modular OSC / MIDI controller",
|
||||
"version": "1.30.0-beta5",
|
||||
"version": "1.30.0-beta6",
|
||||
"author": {
|
||||
"name": "Jean-Emmanuel Doucet",
|
||||
"email": "jean-emmanuel@ammd.net"
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
font-style: normal;
|
||||
font-weight: 900;
|
||||
font-display: block;
|
||||
src: url("./fa-solid-900.woff2?__OSC_ASSET__=1") format("woff2"); }
|
||||
src: url("./fa-solid-900.woff2") format("woff2"); }
|
||||
|
||||
.fa,
|
||||
.fas,
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@
|
|||
font-family: 'Roboto';
|
||||
font-style: normal;
|
||||
font-weight: 700;
|
||||
src: url('./Roboto-Bold.woff2?__OSC_ASSET__=1') format('woff2');
|
||||
src: url('./Roboto-Bold.woff2') format('woff2');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Roboto';
|
||||
font-style: normal;
|
||||
font-weight: 500;
|
||||
src: url('./Roboto-Medium.woff2?__OSC_ASSET__=1') format('woff2');
|
||||
src: url('./Roboto-Medium.woff2') format('woff2');
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -17,19 +17,19 @@
|
|||
font-family: 'Roboto';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: url('./Roboto-Regular.woff2?__OSC_ASSET__=1') format('woff2');
|
||||
src: url('./Roboto-Regular.woff2') format('woff2');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Roboto';
|
||||
font-style: normal;
|
||||
font-weight: 100;
|
||||
src: url('./Roboto-Light.woff2?__OSC_ASSET__=1') format('woff2');
|
||||
src: url('./Roboto-Light.woff2') format('woff2');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Roboto Mono';
|
||||
font-style: normal;
|
||||
font-weight: 500;
|
||||
src: url('./roboto-mono.woff?__OSC_ASSET__=1') format('woff');
|
||||
src: url('./roboto-mono.woff') format('woff');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ module.exports = {
|
|||
output: [
|
||||
{
|
||||
dir: 'app/client/',
|
||||
chunkFileNames: `[name]-${package.version}.js`,
|
||||
entryFileNames: `[name]-${package.version}.js`,
|
||||
chunkFileNames: `[name].js`,
|
||||
entryFileNames: `[name].js`,
|
||||
format: 'es',
|
||||
sourcemap: true,
|
||||
sourcemapExcludeSources: true
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ module.exports = {
|
|||
output: [
|
||||
{
|
||||
dir: 'app/launcher/',
|
||||
chunkFileNames: `[name]-${package.version}.js`,
|
||||
chunkFileNames: `[name].js`,
|
||||
format: 'commonjs',
|
||||
sourcemap: true,
|
||||
sourcemapExcludeSources: true,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ module.exports = {
|
|||
output: [
|
||||
{
|
||||
dir: 'app/server/',
|
||||
chunkFileNames: `[name]-${package.version}.js`,
|
||||
chunkFileNames: `[name].js`,
|
||||
format: 'commonjs',
|
||||
sourcemap: true,
|
||||
sourcemapExcludeSources: true,
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@
|
|||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||
<meta name="theme-color" content="black">
|
||||
<link rel="apple-touch-icon" href="/assets/logo.png?__OSC_ASSET__=1&version=${version}" />
|
||||
<link rel="stylesheet" type="text/css" href="/assets/open-stage-control.css?__OSC_ASSET__=1&version=${version}" hot-reload/>
|
||||
<link rel="stylesheet" type="text/css" href="/theme.css?__OSC_ASSET__=1&version=${version}" hot-reload/>
|
||||
<link rel="stylesheet" type="text/css" href="/assets/fonts/fontawesome.min.css?__OSC_ASSET__=1&version=${version}"/>
|
||||
<link rel="stylesheet" type="text/css" href="/assets/fonts/fa-solid.css?__OSC_ASSET__=1&version=${version}"/>
|
||||
<link rel="stylesheet" type="text/css" href="/assets/fonts/roboto.css?__OSC_ASSET__=1&version=${version}"/>
|
||||
<link rel="shortcut icon" href="/assets/favicon.png?__OSC_ASSET__=1&version=${version}"/>
|
||||
<script src="/client/ace/ace.js?__OSC_ASSET__=1&version=${version}"></script>
|
||||
<script type="module" defer src="/client/index-${version}.js"></script>
|
||||
<link rel="apple-touch-icon" href="/assets/logo.png" />
|
||||
<link rel="stylesheet" type="text/css" href="/assets/open-stage-control.css" hot-reload/>
|
||||
<link rel="stylesheet" type="text/css" href="/assets/theme.css" hot-reload/>
|
||||
<link rel="stylesheet" type="text/css" href="/assets/fonts/fontawesome.min.css"/>
|
||||
<link rel="stylesheet" type="text/css" href="/assets/fonts/fa-solid.css"/>
|
||||
<link rel="stylesheet" type="text/css" href="/assets/fonts/roboto.css"/>
|
||||
<link rel="shortcut icon" href="/assets/favicon.png"/>
|
||||
<script src="/client/ace/ace.js"></script>
|
||||
<script type="module" defer src="/client/index.js"></script>
|
||||
</head>
|
||||
|
||||
<body class="editor-disabled" spellcheck="false">
|
||||
|
|
|
|||
|
|
@ -127,7 +127,21 @@ class WebServer extends EventEmitter {
|
|||
|
||||
res.sendFile = (path)=>{
|
||||
var fpath = path.split('?')[0]
|
||||
if (!fs.existsSync(fpath)) throw `File "${fpath}" not found.`
|
||||
var stats = fs.statSync(fpath)
|
||||
if (!stats || !stats.isFile()) {
|
||||
throw `File "${fpath}" not found.`
|
||||
}
|
||||
var lastModified = new Date(stats.mtime)
|
||||
lastModified.setMilliseconds(0)
|
||||
res.setHeader('Cache-Control', 'no-cache')
|
||||
res.setHeader("Last-Modified", lastModified.toUTCString())
|
||||
if (
|
||||
req.headers['if-modified-since'] && new Date(req.headers['if-modified-since']).getTime() >= lastModified.getTime()
|
||||
) {
|
||||
res.statusCode = 304
|
||||
res.end()
|
||||
return
|
||||
}
|
||||
return send(req, fpath).pipe(res)
|
||||
}
|
||||
|
||||
|
|
@ -152,6 +166,7 @@ class WebServer extends EventEmitter {
|
|||
clientOptions[k] = v
|
||||
}
|
||||
}
|
||||
res.setHeader('Cache-Control', 'no-store')
|
||||
fs.createReadStream(path.resolve(__dirname + '/../../client/index.html'))
|
||||
.pipe(replaceStream('</body>', `
|
||||
<script>
|
||||
|
|
@ -166,8 +181,7 @@ class WebServer extends EventEmitter {
|
|||
} else {
|
||||
|
||||
if (
|
||||
url.indexOf('__OSC_ASSET__=1') != -1 ||
|
||||
url.indexOf('open-stage-control-client.js.map') != -1 ||
|
||||
url.indexOf('/assets/') == 0 ||
|
||||
url.indexOf('/client/') == 0
|
||||
) {
|
||||
|
||||
|
|
@ -176,6 +190,16 @@ class WebServer extends EventEmitter {
|
|||
if (url.indexOf('theme.css') != -1) {
|
||||
|
||||
res.setHeader('Content-Type', 'text/css')
|
||||
|
||||
var etag = settings.read('theme') ? theme.hash : 'empty-theme'
|
||||
res.setHeader('Cache-Control', 'no-cache')
|
||||
res.setHeader('ETag', etag)
|
||||
if (req.headers['if-none-match'] && req.headers['if-none-match'] === etag) {
|
||||
res.statusCode = 304
|
||||
res.end()
|
||||
return
|
||||
}
|
||||
|
||||
if (settings.read('theme')) {
|
||||
let str = theme.get(),
|
||||
buf = Buffer.from && Buffer.from !== Uint8Array.from ? Buffer.from(str) : new Buffer(str)
|
||||
|
|
@ -187,7 +211,6 @@ class WebServer extends EventEmitter {
|
|||
|
||||
} else {
|
||||
|
||||
if (this.prod) res.setHeader('Cache-Control', 'public, max-age=2592000')
|
||||
try {
|
||||
res.sendFile(path.resolve(__dirname + '/../../' + url))
|
||||
return true
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import fs from 'fs'
|
|||
import path from 'path'
|
||||
import chokidar from 'chokidar'
|
||||
import {EventEmitter} from 'events'
|
||||
import crypto from 'crypto'
|
||||
import * as settings from './settings.mjs'
|
||||
|
||||
class Theme extends EventEmitter {
|
||||
|
|
@ -17,6 +18,7 @@ class Theme extends EventEmitter {
|
|||
this.watcher = null
|
||||
this.themes = settings.read('theme') || []
|
||||
this.files = []
|
||||
this.hash = ''
|
||||
|
||||
if (!this.themes.length) return this
|
||||
|
||||
|
|
@ -66,6 +68,8 @@ class Theme extends EventEmitter {
|
|||
|
||||
}
|
||||
|
||||
this.hash = crypto.createHash('sha1').update(this.get()).digest('base64')
|
||||
|
||||
}
|
||||
|
||||
get() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue