18 lines
601 B
JavaScript
18 lines
601 B
JavaScript
|
|
const fs = require('node:fs');
|
||
|
|
const path = require('node:path');
|
||
|
|
const dotenv = require('dotenv');
|
||
|
|
|
||
|
|
const rootEnvPath = path.resolve(__dirname, '../../.env');
|
||
|
|
const outputPath = path.resolve(__dirname, '../public/env.js');
|
||
|
|
|
||
|
|
dotenv.config({ path: rootEnvPath });
|
||
|
|
|
||
|
|
const runtimeEnv = {
|
||
|
|
PRIVATECHAT_CLIENT_SERVER_URL: process.env.PRIVATECHAT_CLIENT_SERVER_URL ?? 'http://localhost:3000',
|
||
|
|
};
|
||
|
|
|
||
|
|
const fileContents = `window.__PRIVATECHAT_ENV__ = ${JSON.stringify(runtimeEnv, null, 2)};\n`;
|
||
|
|
|
||
|
|
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
||
|
|
fs.writeFileSync(outputPath, fileContents, 'utf8');
|