Skip to content

Commit

Permalink
Merge pull request #285 from dappnode/pablo/allow-origin-to-brain-ui
Browse files Browse the repository at this point in the history
Allow origin in brain UI
  • Loading branch information
pablomendezroyo authored Jan 31, 2024
2 parents bc4a347 + a1541ff commit 15bb30e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 4 additions & 1 deletion packages/brain/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ export const brainDb = new BrainDataBase(
);

// Start server APIs
const uiServer = startUiServer(path.resolve(__dirname, params.uiBuildDirName));
const uiServer = startUiServer(
path.resolve(__dirname, params.uiBuildDirName),
network
);
const launchpadServer = startLaunchpadApi();

await brainDb.initialize(signerApi, validatorApi);
Expand Down
19 changes: 16 additions & 3 deletions packages/brain/src/modules/apiServers/ui/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RpcPayload, RpcResponse } from "@stakingbrain/common";
import { Network, RpcPayload, RpcResponse } from "@stakingbrain/common";
import cors from "cors";
import express from "express";
import path from "path";
Expand All @@ -9,7 +9,10 @@ import * as routes from "../../../calls/index.js";
import http from "http";
import { params } from "../../../params.js";

export function startUiServer(uiBuildPath: string): http.Server {
export function startUiServer(
uiBuildPath: string,
network: Network
): http.Server {
const app = express();
const server = http.createServer(app);

Expand Down Expand Up @@ -50,7 +53,17 @@ export function startUiServer(uiBuildPath: string): http.Server {
});

// Express
app.use(cors());
const allowedOrigins = [
"http://my.dappnode",
`http://brain.web3signer${
network === "mainnet" ? "" : "-" + network
}.dappnode`,
];
app.use(
cors({
origin: allowedOrigins,
})
);
app.use(express.json());
app.use(express.static(uiBuildPath));
app.get("*", (req, res) => {
Expand Down

0 comments on commit 15bb30e

Please sign in to comment.