feat(build): bundle frontend with vite and matrix-js-sdk, fix HOST in server.js
This commit is contained in:
1 parent
5ce3b46bab
commit
b6cc9f3465
8 files changed
+3421
-9
No files matched your search
@@ -1,2 +1,4 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
|
dist/
|
||||||
.codesearch/
|
.codesearch/
|
||||||
|
|
||||||
+4
-2
@@ -6,9 +6,9 @@ WORKDIR /app
|
|||||||
|
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
RUN npm ci --omit=dev
|
RUN npm ci
|
||||||
|
|
||||||
COPY server.js tracing.js ./
|
COPY server.js tracing.js vite.config.mjs ./
|
||||||
COPY public/ ./public/
|
COPY public/ ./public/
|
||||||
|
|
||||||
# Inject build release into index.html if APP_RELEASE is specified
|
# Inject build release into index.html if APP_RELEASE is specified
|
||||||
@@ -18,6 +18,8 @@ RUN if [ -n "${APP_RELEASE}" ]; then \
|
|||||||
sed -i "s/window.__APP_RELEASE__ || \"dev\"/\"${APP_RELEASE}\"/g" ./public/index.html; \
|
sed -i "s/window.__APP_RELEASE__ || \"dev\"/\"${APP_RELEASE}\"/g" ./public/index.html; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
RUN npm run build && npm prune --omit=dev
|
||||||
|
|
||||||
ENV PORT=8080 \
|
ENV PORT=8080 \
|
||||||
HOST=0.0.0.0
|
HOST=0.0.0.0
|
||||||
|
|
||||||
|
|||||||
Generated
+3371
File diff suppressed because it is too large.
Load diff
@@ -4,6 +4,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Discord-clone POC: WebRTC voice chat + screen sharing + spatial audio",
|
"description": "Discord-clone POC: WebRTC voice chat + screen sharing + spatial audio",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"build": "vite build",
|
||||||
"start": "node server.js",
|
"start": "node server.js",
|
||||||
"test": "node --test"
|
"test": "node --test"
|
||||||
},
|
},
|
||||||
@@ -16,6 +17,16 @@
|
|||||||
"@opentelemetry/sdk-logs": "^0.222.0",
|
"@opentelemetry/sdk-logs": "^0.222.0",
|
||||||
"@opentelemetry/sdk-node": "^0.222.0",
|
"@opentelemetry/sdk-node": "^0.222.0",
|
||||||
"@opentelemetry/semantic-conventions": "^1.43.0",
|
"@opentelemetry/semantic-conventions": "^1.43.0",
|
||||||
|
"matrix-js-sdk": "^42.4.0",
|
||||||
"ws": "^8.18.0"
|
"ws": "^8.18.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@vitejs/plugin-basic-ssl": "^2.3.0",
|
||||||
|
"esbuild": "^0.28.2",
|
||||||
|
"vite": "^8.3.0",
|
||||||
|
"vite-plugin-node-polyfills": "^0.28.0"
|
||||||
|
},
|
||||||
|
"allowScripts": {
|
||||||
|
"esbuild@0.28.2": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-3
@@ -1,6 +1,4 @@
|
|||||||
/* gibbz voice POC — WebRTC mesh voice + screen share + spatial audio.
|
import * as matrixcs from 'matrix-js-sdk';
|
||||||
POC shortcuts: no auth (voice), no E2E crypto (matrix text), single audio context. */
|
|
||||||
import * as matrixcs from 'https://cdn.jsdelivr.net/npm/matrix-js-sdk@42.4.0/lib/browser-index.min.js';
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// state
|
// state
|
||||||
|
|||||||
+1
-1
@@ -120,6 +120,6 @@
|
|||||||
|
|
||||||
<div id="toasts"></div>
|
<div id="toasts"></div>
|
||||||
|
|
||||||
<script type="module" src="app.js?v=11"></script>
|
<script type="module" src="/app.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -10,7 +10,9 @@ const { WebSocketServer } = require('ws');
|
|||||||
|
|
||||||
const PORT = Number(process.env.PORT || 8080);
|
const PORT = Number(process.env.PORT || 8080);
|
||||||
const HOST = process.env.HOST || '0.0.0.0';
|
const HOST = process.env.HOST || '0.0.0.0';
|
||||||
const PUBLIC_DIR = path.join(__dirname, 'public');
|
const STATIC_DIR = fs.existsSync(path.join(__dirname, 'dist'))
|
||||||
|
? path.join(__dirname, 'dist')
|
||||||
|
: path.join(__dirname, 'public');
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// ICE configuration: env-driven, full JSON override wins.
|
// ICE configuration: env-driven, full JSON override wins.
|
||||||
@@ -74,8 +76,8 @@ const MIME = {
|
|||||||
function serveStatic(req, res) {
|
function serveStatic(req, res) {
|
||||||
const urlPath = decodeURIComponent(new URL(req.url, 'http://x').pathname);
|
const urlPath = decodeURIComponent(new URL(req.url, 'http://x').pathname);
|
||||||
let rel = urlPath === '/' ? '/index.html' : urlPath;
|
let rel = urlPath === '/' ? '/index.html' : urlPath;
|
||||||
const file = path.normalize(path.join(PUBLIC_DIR, rel));
|
const file = path.normalize(path.join(STATIC_DIR, rel));
|
||||||
if (!file.startsWith(PUBLIC_DIR)) {
|
if (!file.startsWith(STATIC_DIR)) {
|
||||||
res.writeHead(403).end('forbidden');
|
res.writeHead(403).end('forbidden');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { defineConfig } from 'vite';
|
||||||
|
import { nodePolyfills } from 'vite-plugin-node-polyfills';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
root: 'public',
|
||||||
|
plugins: [
|
||||||
|
nodePolyfills({
|
||||||
|
include: ['buffer', 'crypto', 'events', 'stream', 'util'],
|
||||||
|
globals: {
|
||||||
|
Buffer: true,
|
||||||
|
global: true,
|
||||||
|
process: true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
build: {
|
||||||
|
outDir: '../dist',
|
||||||
|
emptyOutDir: true,
|
||||||
|
target: 'esnext',
|
||||||
|
minify: 'esbuild',
|
||||||
|
rollupOptions: {
|
||||||
|
input: path.resolve(import.meta.dirname, 'public/index.html'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
Reference in new issue
Block a user