Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serve Switchboard from Subdirectories #108

Merged
merged 52 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
911f2b1
fix: await add fees
froid1911 Mar 15, 2024
69f20b6
chore: removed some not required checks
froid1911 Mar 15, 2024
ed714e9
refactor: createMany fees at once
froid1911 Mar 15, 2024
07772f3
fix: await add fees (#106)
froid1911 Mar 16, 2024
de28717
feat: added base path to next config
froid1911 Mar 21, 2024
82c0c67
feat: added assetPrefix
froid1911 Mar 21, 2024
a897f67
fix: sub dir deployment frontend
froid1911 Mar 21, 2024
2e97e6c
fix: updated docker build arg
froid1911 Mar 21, 2024
4831ef7
fix: base path
froid1911 Mar 21, 2024
13d39d8
feat: introduce path for nginx proxy
froid1911 Mar 21, 2024
c1ee8d1
feat: introduce path for nginx proxy
froid1911 Mar 21, 2024
f79b4a6
chore: move frontend to end of nginx
froid1911 Mar 21, 2024
36ada29
fix: base path
froid1911 Mar 21, 2024
f1e742c
fix: base path for backend routes
froid1911 Mar 21, 2024
dc67487
fix: rewrites to proper base path
froid1911 Mar 21, 2024
d8e5720
fix: rewrite rules
froid1911 Mar 21, 2024
6f88f0d
feat: added express router for base path
froid1911 Mar 22, 2024
5b7332d
fix: removed rewrite rules
froid1911 Mar 22, 2024
aaeaa31
feat: added basepath to explorer endpoint
froid1911 Mar 22, 2024
3a731ac
fix: endpoint base path
froid1911 Mar 22, 2024
c1d9652
fix: base path nginx router switchboard
froid1911 Mar 22, 2024
e42b3e1
fix: favicon path
froid1911 Mar 22, 2024
75fb4ef
fix: base path for assets
froid1911 Mar 22, 2024
58eb798
ci: added arbitrum deployment pipeline
froid1911 Mar 20, 2024
b495d47
chore: removed codeowners file
froid1911 Mar 20, 2024
4f48407
cicd: added staging deployment
froid1911 Mar 22, 2024
34596c5
chore: bump deps
froid1911 Mar 27, 2024
4976115
fix: added sales proceeds
froid1911 Mar 27, 2024
9cfcddc
chore: wording
froid1911 Mar 27, 2024
bea84e8
fix: name in assets not found
froid1911 Mar 28, 2024
96e3c2b
feat: in memory cache for drives and transmitters
froid1911 Mar 29, 2024
90a7b31
chore: cleanup
froid1911 Mar 29, 2024
c0d4b1d
chore: cleanup
froid1911 Mar 29, 2024
5f562b2
chore: removed set transmitter fn
froid1911 Mar 29, 2024
7051545
feat: log listener operation error
acaldas Mar 29, 2024
f6dc104
feat: updated deps and small ts improvements
acaldas Mar 29, 2024
9c86c34
chore: updated document drive deb and prisma schema
froid1911 Apr 1, 2024
913804e
feat: error logging
froid1911 Apr 2, 2024
b362cf5
chore: catch drive init exceptions
froid1911 Apr 2, 2024
9b1e437
chore: cleanup
froid1911 Apr 2, 2024
2ee3c74
feat: update deps
acaldas Apr 3, 2024
877bd53
feat: documents query
froid1911 Apr 2, 2024
4e2ff15
feat: added query to fetch all documents at once from a drive
froid1911 Apr 2, 2024
840ae2b
feat: added sentry node
froid1911 Apr 3, 2024
42ce003
chore: removed comments
froid1911 Apr 3, 2024
dcafa3a
chore: clear cache
froid1911 Apr 3, 2024
45fd576
fix(apollo): document operations
froid1911 Apr 3, 2024
0ba6f6a
fix: document operations type
froid1911 Apr 3, 2024
1322e93
feat: added makerdao and updated powerhouse deployments pipeline
froid1911 Apr 4, 2024
0b5d19b
fix: updated docker build arg
froid1911 Mar 21, 2024
9d23200
feat: added express router for base path
froid1911 Mar 22, 2024
215801b
Merge branch 'main' into staging
froid1911 Apr 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-and-deploy-powerhouse-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
Expand Down
26 changes: 22 additions & 4 deletions api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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: {
Expand All @@ -62,5 +80,5 @@ export const createApp = (): Express => {
}
);

return app;
return { app, router };
};
11 changes: 8 additions & 3 deletions api/src/graphql/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,17 @@ const createApolloDriveServer = (): ApolloServer<DriveContext> => new ApolloServ

export const startServer = async (
app: express.Application,
router: express.Router,
): Promise<Server> => {
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<cors.CorsRequest>(),
cookierParser(undefined, { decode: (value: string) => value }),
Expand All @@ -64,7 +65,7 @@ export const startServer = async (
}),
);

app.use(
router.use(
'/d/:driveId',
cors<cors.CorsRequest>(),
cookierParser(undefined, { decode: (value: string) => value }),
Expand All @@ -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}`);
});
Expand Down
4 changes: 2 additions & 2 deletions api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
35 changes: 19 additions & 16 deletions api/src/modules/real-world-assets/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -713,16 +713,19 @@ const surgicalOperations: Record<string, (input: any, portfolio: RWAPortfolio, p

"ADD_FEES_TO_GROUP_TRANSACTION": async (input: AddFeesToGroupTransactionInput, portfolio: RWAPortfolio, prisma: Prisma.TransactionClient) => {
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 });
Expand All @@ -742,8 +745,8 @@ const surgicalOperations: Record<string, (input: any, portfolio: RWAPortfolio, p
data: {
...fee,
portfolioId: portfolio.id,
groupTransactionId: input.id ?? undefined,
id: fee.id ?? undefined
groupTransactionId: input.id,
id: fee.id
}
});
}
Expand Down
4 changes: 4 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ WORKDIR /opt/app
COPY . .
COPY --from=deps /opt/app/node_modules ./node_modules
RUN npm install -g pnpm
ARG BASE_PATH=""
ENV BASE_PATH=${BASE_PATH}
RUN pnpm build

# Production image, copy all the files and run next
Expand All @@ -26,6 +28,8 @@ FROM node:lts-alpine AS runner
ARG X_TAG
WORKDIR /opt/app
ENV NODE_ENV=production
ARG BASE_PATH=""
ENV BASE_PATH=${BASE_PATH}
EXPOSE 3000
COPY --from=builder /opt/app/next.config.mjs ./
COPY --from=builder /opt/app/public ./public
Expand Down
3 changes: 3 additions & 0 deletions frontend/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const nextConfig = {
NEXT_PUBLIC_SWITCHBOARD_GRAPHQL_HOST:
process.env.NEXT_PUBLIC_SWITCHBOARD_GRAPHQL_HOST ||
"https://ph-switchboard-nginx-prod-c84ebf8c6e3b.herokuapp.com",
NEXT_PUBLIC_BASE_PATH: process.env.BASE_PATH ?? "",
},
basePath: process.env.BASE_PATH ?? "/",
assetPrefix: process.env.BASE_PATH ?? "/",
};

export default nextConfig;
Binary file removed frontend/src/app/favicon.ico
Binary file not shown.
9 changes: 6 additions & 3 deletions frontend/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ export default function RootLayout({
<link
rel="apple-touch-icon"
sizes="180x180"
href="/apple-touch-icon.png"
href={`${process.env.NEXT_PUBLIC_BASE_PATH}/apple-touch-icon.png`}
/>

<link
rel="icon"
type="image/png"
sizes="16x16"
href="/favicon-16x16.png"
href={`${process.env.NEXT_PUBLIC_BASE_PATH}/favicon-16x16.png`}
/>
<link
rel="manifest"
href={`${process.env.NEXT_PUBLIC_BASE_PATH}/site.webmanifest`}
/>
<link rel="manifest" href="/site.webmanifest" />
</head>
<body className={inter.className}>
<div className="bg-gray-100">
Expand Down
18 changes: 10 additions & 8 deletions frontend/src/components/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -40,7 +41,13 @@ export default function Header() {
<div className="flex items-start">
<SwitchboardLink href="/">
<div className="flex flex-row items-center">
<img src="/assets/logo.svg" className="w-10" />
<Image
src={logo}
alt="Switchboard Logo"
className="w-10"
width="32"
height="32"
/>
Switchboard API
</div>
</SwitchboardLink>
Expand Down Expand Up @@ -87,12 +94,7 @@ export default function Header() {
href="https://github.com/powerhouse-inc/switchboard-boilerplate"
target="_blank"
>
<Image
src="/assets/github.svg"
alt="GitHub"
width="32"
height="32"
/>
<Image src={github} alt="GitHub" width="32" height="32" />
</Link>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -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;'

25 changes: 11 additions & 14 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
}

Loading