Add frontend URL to config.

This commit is contained in:
Sage Vaillancourt 2022-09-08 21:51:10 -04:00
parent 76ab13b385
commit 75e81e7956
2 changed files with 12 additions and 14 deletions

8
app.js
View File

@ -48,7 +48,7 @@ console.log('CLUSTERS', clusters)
const app = express(); const app = express();
app.use(cors({ app.use(cors({
origin: 'http://localhost:5173' origin: config.frontendUrl,
})) }))
app.use(logger('dev')); app.use(logger('dev'));
app.use(express.json()); app.use(express.json());
@ -155,14 +155,12 @@ const oneShotSearch = async ({ kafka, socket, topic, maxItems }) =>
onBatchDone: buildSocketMessageSender({ socket, type: 'item_count' }) onBatchDone: buildSocketMessageSender({ socket, type: 'item_count' })
}) })
/** /** @type {WebSocketServer} */
* @type {WebSocketServer}
*/
const wsServer = new ws.WebSocketServer({ const wsServer = new ws.WebSocketServer({
noServer: true noServer: true
}) })
/** @type {Map<WebSocket, ({consumer: Consumer, cluster: { kafka, admin, config }})>} */ /** @type {Map<WebSocket, ({consumer: kafka.Consumer, cluster: { kafka, admin, config }})>} */
const consumers = new Map() const consumers = new Map()
buildEscape(consumers, clusters) buildEscape(consumers, clusters)

View File

@ -5,19 +5,19 @@ const homedir = require('os').homedir()
const configFilePath = homedir + path.sep + '.kafka-dance' const configFilePath = homedir + path.sep + '.kafka-dance'
const emptyConfig = () => ({ const emptyConfig = () => ({
clusters: {} clusters: {},
frontendUrl: 'http://localhost:5173',
}) })
const readConfig = () => { const readConfig = () => {
if (!fs.existsSync(configFilePath)) { if (fs.existsSync(configFilePath)) {
return emptyConfig()
}
try { try {
return JSON.parse(fs.readFileSync(configFilePath).toString()) return JSON.parse(fs.readFileSync(configFilePath).toString())
} catch (e) { } catch (e) {
console.error(e.toString()) console.error(e.toString())
return emptyConfig()
} }
}
return emptyConfig()
} }
const storeConfig = async config => const storeConfig = async config =>