mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-14 11:53:49 +00:00
Merge branch 'master' into port-colision
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import * as esbuild from 'esbuild';
|
||||
import { esbuildCommon } from './esbuildCommon.js';
|
||||
|
||||
await esbuild.build({
|
||||
...esbuildCommon,
|
||||
entryPoints: ['src/app.ts'],
|
||||
minify: false,
|
||||
dropLabels: [],
|
||||
outfile: 'dist/index.cjs',
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
import * as esbuild from 'esbuild';
|
||||
import { esbuildCommon } from './esbuildCommon.js';
|
||||
|
||||
await esbuild.build({
|
||||
...esbuildCommon,
|
||||
entryPoints: ['src/index.ts'],
|
||||
outfile: 'dist/docker.cjs',
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
import * as esbuild from 'esbuild';
|
||||
import { esbuildCommon } from './esbuildCommon.js';
|
||||
|
||||
await esbuild.build({
|
||||
...esbuildCommon,
|
||||
entryPoints: ['src/app.ts'],
|
||||
outfile: 'dist/index.cjs',
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
export const esbuildCommon = {
|
||||
logLevel: 'error',
|
||||
platform: 'node',
|
||||
target: ['node20'],
|
||||
format: 'cjs',
|
||||
bundle: true,
|
||||
minify: true,
|
||||
legalComments: 'external',
|
||||
dropLabels: ['DEV'],
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"ext": "js,json,ts"
|
||||
}
|
||||
@@ -33,7 +33,7 @@
|
||||
"@types/ws": "^8.5.10",
|
||||
"@typescript-eslint/eslint-plugin": "catalog:",
|
||||
"@typescript-eslint/parser": "catalog:",
|
||||
"esbuild": "^0.19.10",
|
||||
"esbuild": "^0.24.0",
|
||||
"eslint": "catalog:",
|
||||
"eslint-plugin-prettier": "catalog:",
|
||||
"ontime-types": "workspace:*",
|
||||
@@ -43,7 +43,7 @@
|
||||
"ts-essentials": "^9.4.1",
|
||||
"tsx": "^4.16.2",
|
||||
"typescript": "catalog:",
|
||||
"vitest": "^1.6.0"
|
||||
"vitest": "catalog:"
|
||||
},
|
||||
"scripts": {
|
||||
"addversion": "node -p \"'export const ONTIME_VERSION = ' + JSON.stringify(require('../../package.json').version) + ';'\" > src/ONTIME_VERSION.js",
|
||||
@@ -51,12 +51,11 @@
|
||||
"dev": "cross-env NODE_ENV=development tsx watch ./src/index.ts",
|
||||
"dev:inspect": "cross-env NODE_ENV=development tsx watch --inspect ./src/index.ts",
|
||||
"dev:test": "cross-env IS_TEST=true tsx ./src/index.ts",
|
||||
"build": "esbuild src/app.ts --log-level=error --platform=node --format=cjs --bundle --minify --legal-comments=external --drop-labels=DEV --outfile=dist/index.cjs",
|
||||
"build:electron": "esbuild src/app.ts --log-level=error --platform=node --format=cjs --bundle --minify --legal-comments=external --drop-labels=DEV --outfile=dist/index.cjs",
|
||||
"build:local": "esbuild src/app.ts --log-level=error --platform=node --format=cjs --bundle --minify --legal-comments=external --drop-labels=DEV --outfile=dist/index.cjs",
|
||||
"build:docker": "esbuild src/index.ts --log-level=error --platform=node --format=cjs --minify --bundle --legal-comments=external --drop-labels=DEV --outfile=dist/docker.cjs",
|
||||
"build:localdocker": "cross-env NODE_ENV=local esbuild src/index.ts --log-level=error --platform=node --format=cjs --minify --bundle --legal-comments=external --drop-labels=DEV --outfile=dist/docker.cjs",
|
||||
"build:debug": "esbuild src/app.ts --platform=node --format=cjs --bundle --legal-comments=external --outfile=dist/index.cjs",
|
||||
"build": "node esbuild.electron.js",
|
||||
"build:electron": "node esbuild.electron.js",
|
||||
"build:local": "node esbuild.dev.js",
|
||||
"build:docker": "node esbuild.docker.js",
|
||||
"build:localdocker": "cross-env NODE_ENV=local node esbuild.docker.js",
|
||||
"lint": "eslint . --quiet",
|
||||
"test": "cross-env IS_TEST=true vitest",
|
||||
"test:pipeline": "cross-env IS_TEST=true vitest run",
|
||||
|
||||
+21
-6
@@ -6,11 +6,11 @@ import expressStaticGzip from 'express-static-gzip';
|
||||
import http, { Server } from 'http';
|
||||
import cors from 'cors';
|
||||
import serverTiming from 'server-timing';
|
||||
import { extname, resolve } from 'path';
|
||||
|
||||
// import utils
|
||||
import { resolve } from 'path';
|
||||
import { publicDir, srcDir } from './setup/index.js';
|
||||
import { environment, isProduction } from './externals.js';
|
||||
import { environment, isProduction, updateRouterPrefix } from './externals.js';
|
||||
import { ONTIME_VERSION } from './ONTIME_VERSION.js';
|
||||
import { consoleSuccess, consoleHighlight, consoleError } from './utils/console.js';
|
||||
|
||||
@@ -53,9 +53,12 @@ if (!canLog) {
|
||||
console.log(`Ontime public directory at ${publicDir.root} `);
|
||||
}
|
||||
|
||||
// calls an update to the client router prefix
|
||||
updateRouterPrefix();
|
||||
|
||||
// Create express APP
|
||||
const app = express();
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
if (!isProduction) {
|
||||
// log server timings to requests
|
||||
app.use(serverTiming());
|
||||
}
|
||||
@@ -89,10 +92,22 @@ app.use(
|
||||
expressStaticGzip(srcDir.clientDir, {
|
||||
enableBrotli: true,
|
||||
orderPreference: ['br'],
|
||||
// when we build the client all the react subfiles will get a hashed name we can the immutable tag
|
||||
// when we build the client the file names contain a unique hash for the build
|
||||
// this allows us to use the immutable tag
|
||||
// as the contents of a build file will never change without also changing its name
|
||||
// so the client dose not need to revalidate the file contetnts with the server
|
||||
serveStatic: { etag: false, lastModified: false, immutable: true, maxAge: '1y' },
|
||||
// meaning that the client does not need to revalidate the contents with the server
|
||||
serveStatic: {
|
||||
etag: false,
|
||||
lastModified: false,
|
||||
immutable: true,
|
||||
maxAge: '1y',
|
||||
setHeaders: (res, file) => {
|
||||
// make sure the HTML files are always revalidated
|
||||
if (extname(file) === '.html') {
|
||||
res.setHeader('Cache-Control', 'public, max-age=0');
|
||||
}
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
* This file contains a list of constants that may need to be resolved at runtime
|
||||
*/
|
||||
|
||||
import { readFileSync, writeFileSync } from 'node:fs';
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
// =================================================
|
||||
// resolve running environment
|
||||
const env = process.env.NODE_ENV || 'production';
|
||||
@@ -10,3 +13,25 @@ export const isTest = Boolean(process.env.IS_TEST);
|
||||
export const environment = isTest ? 'test' : env;
|
||||
export const isDocker = env === 'docker';
|
||||
export const isProduction = isDocker || (env === 'production' && !isTest);
|
||||
|
||||
/**
|
||||
* Updates the router prefix in the index.html file
|
||||
* This is only needed in the cloud environment where the client is not at the root segment
|
||||
* ie: https://cloud.getontime.com/client-hash/timer
|
||||
*/
|
||||
export function updateRouterPrefix(prefix: string | undefined = process.env.ROUTER_PREFIX) {
|
||||
if (!prefix) {
|
||||
return;
|
||||
}
|
||||
|
||||
const indexFile = resolve('.', 'client', 'index.html');
|
||||
try {
|
||||
const data = readFileSync(indexFile, { encoding: 'utf-8', flag: 'r' }).replace(
|
||||
/<base href="[^"]*">/g,
|
||||
`<base href="${prefix}>"`,
|
||||
);
|
||||
writeFileSync(indexFile, data, { encoding: 'utf-8', flag: 'w' });
|
||||
} catch (_error) {
|
||||
/** unhandled */
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user