diff --git a/.github/workflows/build-and-deploy-powerhouse-staging.yaml b/.github/workflows/build-and-deploy-powerhouse-staging.yaml index 8e46304a..f138bb44 100644 --- a/.github/workflows/build-and-deploy-powerhouse-staging.yaml +++ b/.github/workflows/build-and-deploy-powerhouse-staging.yaml @@ -30,7 +30,7 @@ jobs: dockerfile_directory: ./frontend dockerfile_name: Dockerfile process_type: web - docker_options: "--build-arg NEXT_PUBLIC_SWITCHBOARD_GRAPHQL_HOST=${{ secrets.NEXT_PUBLIC_SWITCHBOARD_GRAPHQL_HOST }}" + docker_options: "--build-arg NEXT_PUBLIC_SWITCHBOARD_GRAPHQL_HOST=${{ secrets.NEXT_PUBLIC_SWITCHBOARD_GRAPHQL_HOST }} --build-arg BASE_PATH=/makerdao/switchboard" - name: Build, Push and Release NGINX to Heroku. # Your custom step name uses: gonuit/heroku-docker-deploy@v1.3.3 with: diff --git a/api/src/app.ts b/api/src/app.ts index f585f233..7e570880 100644 --- a/api/src/app.ts +++ b/api/src/app.ts @@ -12,9 +12,26 @@ import { nodeProfilingIntegration } from "@sentry/profiling-node"; const logger = getChildLogger({ msgPrefix: 'APP' }); const startupTime = new Date(); -export const createApp = (): Express => { +export const createApp = (): { app: Express, router: express.Router } => { logger.debug('Creating app'); const app = express(); + const router = express.Router(); + + if (process.env.SENTRY_DSN) { + Sentry.init({ + dsn: process.env.SENTRY_DSN, + integrations: [ + nodeProfilingIntegration(), + new Sentry.Integrations.Express({ + app, + }), + ], + tracesSampleRate: 1.0, + }); + + app.use(Sentry.Handlers.requestHandler()); + app.use(Sentry.Handlers.tracingHandler()); + } if (process.env.SENTRY_DSN) { Sentry.init({ @@ -48,11 +65,12 @@ export const createApp = (): Express => { }); }); - app.get( + router.get( '/explorer/:driveId?', (req, res) => { res.setHeader('Content-Type', 'text/html') - const endpoint = req.params.driveId !== undefined ? `/d/${req.params.driveId}` : '/drives' + const basePath = process.env.BASE_PATH === "/" ? "" : process.env.BASE_PATH || ''; + const endpoint = `${basePath}${req.params.driveId !== undefined ? `/d/${req.params.driveId}` : '/drives'}` res.send(renderPlaygroundPage({ endpoint: endpoint, settings: { @@ -62,5 +80,5 @@ export const createApp = (): Express => { } ); - return app; + return { app, router }; }; diff --git a/api/src/graphql/server/index.ts b/api/src/graphql/server/index.ts index c551997a..44d36dde 100644 --- a/api/src/graphql/server/index.ts +++ b/api/src/graphql/server/index.ts @@ -45,16 +45,17 @@ const createApolloDriveServer = (): ApolloServer => new ApolloServ export const startServer = async ( app: express.Application, + router: express.Router, ): Promise => { logger.debug('Starting server'); - const httpServer = createHttpServer(app); + const apolloIndex = createApolloIndexServer(); const apolloDrive = createApolloDriveServer(); await apolloIndex.start(); await apolloDrive.start(); - app.use( + router.use( '/drives', cors(), cookierParser(undefined, { decode: (value: string) => value }), @@ -64,7 +65,7 @@ export const startServer = async ( }), ); - app.use( + router.use( '/d/:driveId', cors(), cookierParser(undefined, { decode: (value: string) => value }), @@ -74,10 +75,14 @@ export const startServer = async ( }), ); + const basePath = process.env.BASE_PATH || '/'; + app.use(basePath, router); app.use(errorHandler); if (process.env.SENTRY_DSN) { app.use(Sentry.Handlers.errorHandler()); } + + const httpServer = createHttpServer(app); return httpServer.listen({ port: PORT }, () => { logger.info(`Running on ${PORT}`); }); diff --git a/api/src/index.ts b/api/src/index.ts index af367c3a..f0aed6e4 100644 --- a/api/src/index.ts +++ b/api/src/index.ts @@ -4,10 +4,10 @@ import { getChildLogger } from './logger'; const logger = getChildLogger({ msgPrefix: 'SERVER' }); -const application = createApp(); +const { app, router } = createApp(); /* istanbul ignore next @preserve */ -startServer(application) +startServer(app, router) .then((e) => { // Hot Module Replacement if (import.meta.hot) { diff --git a/api/src/modules/real-world-assets/listener.ts b/api/src/modules/real-world-assets/listener.ts index d1b67a71..e3eff820 100644 --- a/api/src/modules/real-world-assets/listener.ts +++ b/api/src/modules/real-world-assets/listener.ts @@ -225,15 +225,15 @@ async function rebuildRwaPortfolio(driveId: string, documentId: string, state: R }) // add fees - for (const fee of transaction.fees ?? []) { - await prisma.rWAGroupTransactionFee.create({ - data: { + if (transaction.fees) { + await prisma.rWAGroupTransactionFee.createMany({ + data: transaction.fees.map(fee => ({ ...fee, portfolioId: portfolioEntity.id, groupTransactionId: transaction.id, id: fee.id ?? undefined - } - }) + })) + }); } // add relationships for fees @@ -713,16 +713,19 @@ const surgicalOperations: Record { logger.debug({ msg: "Adding fee transactions to group transaction", input }); - for (const fee of input.fees ?? []) { - prisma.rWAGroupTransactionFee.create({ - data: { - ...fee, - portfolioId: portfolio.id, - groupTransactionId: input.id ?? undefined, - id: fee.id ?? undefined - } - }); + // add fees + if (!input.fees) { + return; } + + await prisma.rWAGroupTransactionFee.createMany({ + data: input.fees.map(fee => ({ + ...fee, + portfolioId: portfolio.id, + groupTransactionId: input.id, + id: fee.id ?? undefined + })) + }); }, "EDIT_GROUP_TRANSACTION_FEES": async (input: EditGroupTransactionFeesInput, portfolio: RWAPortfolio, prisma: Prisma.TransactionClient) => { logger.debug({ msg: "Editing fee transaction", input }); @@ -742,8 +745,8 @@ const surgicalOperations: Record + -
diff --git a/frontend/src/components/header/header.tsx b/frontend/src/components/header/header.tsx index 95a02f11..23e379fb 100644 --- a/frontend/src/components/header/header.tsx +++ b/frontend/src/components/header/header.tsx @@ -6,7 +6,8 @@ import { useRouter } from "next/navigation"; import { UserCircleIcon } from "@heroicons/react/24/solid"; import Link from "next/link"; import { useEffect, useState } from "react"; - +import logo from "../../../public/assets/logo.svg"; +import github from "../../../public/assets/github.svg"; export default function Header() { const address = authStore((state) => state.address); const gqlToken = authStore((state) => state.gqlToken); @@ -40,7 +41,13 @@ export default function Header() {
- + Switchboard Logo Switchboard API
@@ -87,12 +94,7 @@ export default function Header() { href="https://github.com/powerhouse-inc/switchboard-boilerplate" target="_blank" > - GitHub + GitHub
diff --git a/nginx/Dockerfile b/nginx/Dockerfile index ec40ce06..b0d26341 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -1,10 +1,11 @@ FROM nginx:stable ENV PORT=80 +ENV BASE_PATH="" ENV BACKEND=https://ph-switchboard-api-prod-2f0358a27fa5.herokuapp.com ENV FRONTEND=https://ph-switchboard-frontend-prod-2030e418555a.herokuapp.com ENV WUNDERGRAPH=https://ph-switchboard-wgraph-prod-46a95adab5b7.herokuapp.com COPY nginx.conf /etc/nginx/conf.d/default.conf.template -CMD /bin/sh -c "envsubst '\$PORT,\$BACKEND,\$FRONTEND,\$WUNDERGRAPH' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf" && nginx -g 'daemon off;' +CMD /bin/sh -c "envsubst '\$BASE_PATH,\$PORT,\$BACKEND,\$FRONTEND,\$WUNDERGRAPH' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf" && nginx -g 'daemon off;' diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 1111d51e..0c5aefe2 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -4,34 +4,31 @@ server { listen [::]:${PORT}; server_name localhost; - # frontend - location / { - rewrite /(.*) /$1 break; - proxy_pass ${FRONTEND}; - } - # drives graphql endpoint - location /drives { - rewrite /drives/(.*) /drives/$1 break; + location ${BASE_PATH}/drives { proxy_pass ${BACKEND}; } # drive graphql endpoint - location /d { - rewrite /d/(.*) /d/$1 break; + location ${BASE_PATH}/d { proxy_pass ${BACKEND}; } # GraphQL Explorer - location /explorer { - rewrite /explorer/(.*) /explorer/$1 break; + location ${BASE_PATH}/explorer { proxy_pass ${BACKEND}; } # graphql API composition - location /wundergraph/graphql { - rewrite /wundergraph/graphql /graphql break; + location ${BASE_PATH}/wundergraph/graphql { + rewrite ${BASE_PATH}/wundergraph/graphql /graphql break; proxy_pass ${WUNDERGRAPH}; } + + # frontend + location / { + rewrite /(.*) /$1 break; + proxy_pass ${FRONTEND}; + } }