feat(deploy): run shared toolkit socket
Lint and Build Checks / Lint, Test, and Build (push) Failing after 364h2m28s
Lint and Build Checks / Lint, Test, and Build (push) Failing after 364h2m28s
This commit is contained in:
+87
-22
@@ -1,7 +1,8 @@
|
||||
import path from 'node:path';
|
||||
import type { ServerResponse } from 'node:http';
|
||||
|
||||
import react from '@vitejs/plugin-react';
|
||||
import { defineConfig } from 'vite';
|
||||
import { defineConfig, loadEnv, type PluginOption } from 'vite';
|
||||
|
||||
import packageJson from './package.json';
|
||||
|
||||
@@ -17,25 +18,89 @@ const platformExtensions = [
|
||||
'.json',
|
||||
];
|
||||
|
||||
export default defineConfig({
|
||||
define: {
|
||||
'import.meta.env.VITE_APP_VERSION': JSON.stringify(packageJson.version),
|
||||
},
|
||||
plugins: [react()],
|
||||
resolve: {
|
||||
alias: [{ find: /^react-native$/, replacement: 'react-native-web' }],
|
||||
dedupe: ['react', 'react-dom', 'react-native-web'],
|
||||
extensions: platformExtensions,
|
||||
},
|
||||
optimizeDeps: {
|
||||
exclude: ['react-native-safe-area-context'],
|
||||
},
|
||||
build: {
|
||||
outDir: path.resolve(__dirname, 'dist/renderer'),
|
||||
emptyOutDir: true,
|
||||
},
|
||||
server: {
|
||||
host: '127.0.0.1',
|
||||
port: 5173,
|
||||
},
|
||||
const frontendHealthStartedAt = Date.now();
|
||||
const frontendHealthStartedAtIso = new Date(
|
||||
frontendHealthStartedAt,
|
||||
).toISOString();
|
||||
|
||||
function createFrontendHealthPayload() {
|
||||
return {
|
||||
ok: true,
|
||||
service: 'blb-frontend',
|
||||
version: packageJson.version,
|
||||
startedAt: frontendHealthStartedAtIso,
|
||||
timestamp: new Date().toISOString(),
|
||||
uptimeSeconds: Math.max(
|
||||
0,
|
||||
Math.round((Date.now() - frontendHealthStartedAt) / 1000),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
function writeJsonResponse(
|
||||
response: ServerResponse,
|
||||
statusCode: number,
|
||||
body: object,
|
||||
) {
|
||||
response.writeHead(statusCode, {
|
||||
'Cache-Control': 'no-store',
|
||||
'Content-Type': 'application/json',
|
||||
});
|
||||
response.end(`${JSON.stringify(body)}\n`);
|
||||
}
|
||||
|
||||
function frontendHealthPlugin(): PluginOption {
|
||||
return {
|
||||
name: 'blb-frontend-health',
|
||||
configurePreviewServer(server) {
|
||||
server.middlewares.use((request, response, next) => {
|
||||
if (request.url?.split('?')[0] !== '/health') {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
writeJsonResponse(response, 200, createFrontendHealthPayload());
|
||||
});
|
||||
},
|
||||
configureServer(server) {
|
||||
server.middlewares.use((request, response, next) => {
|
||||
if (request.url?.split('?')[0] !== '/health') {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
writeJsonResponse(response, 200, createFrontendHealthPayload());
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, __dirname, '');
|
||||
const toolkitSocketUrl =
|
||||
env.VITE_TOOLKIT_SOCKET_URL ?? env.TOOLKIT_SOCKET_URL ?? '';
|
||||
|
||||
return {
|
||||
define: {
|
||||
__TOOLKIT_SOCKET_URL__: JSON.stringify(toolkitSocketUrl),
|
||||
'import.meta.env.VITE_APP_VERSION': JSON.stringify(packageJson.version),
|
||||
},
|
||||
plugins: [frontendHealthPlugin(), react()],
|
||||
resolve: {
|
||||
alias: [{ find: /^react-native$/, replacement: 'react-native-web' }],
|
||||
dedupe: ['react', 'react-dom', 'react-native-web'],
|
||||
extensions: platformExtensions,
|
||||
},
|
||||
optimizeDeps: {
|
||||
exclude: ['react-native-safe-area-context'],
|
||||
},
|
||||
build: {
|
||||
outDir: path.resolve(__dirname, 'dist/renderer'),
|
||||
emptyOutDir: true,
|
||||
},
|
||||
server: {
|
||||
host: '127.0.0.1',
|
||||
port: 5173,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user