Skip to content

Commit

Permalink
Fixing bundle - adding polyfill for crypto (#2062)
Browse files Browse the repository at this point in the history
  • Loading branch information
dubwub authored Jan 24, 2025
1 parent daa6ff8 commit cc98a4f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/deploy-fdr-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ env:
FERNIE_SLACK_APP_TOKEN: ${{ secrets.FERNIE_SLACK_APP_TOKEN }}
GITHUB_TOKEN: ${{ secrets.FERN_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.FERN_NPM_TOKEN }}
CLOUDFRONT_KEY_GROUP_ID: ${{ secrets.CLOUDFRONT_KEY_GROUP_ID }}
: ${{ secrets. }}

jobs:
sdk:
Expand All @@ -46,7 +46,7 @@ jobs:
ALGOLIA_SEARCH_INDEX: ${{ secrets.ALGOLIA_SEARCH_INDEX }}
ALGOLIA_SEARCH_V2_DOMAINS: "workato,rohin-bhargava-staging,monite,humanloop,cohere,buildwithfern.com/learn"
ALGOLIA_SEARCH_API_KEY: ${{ secrets.ALGOLIA_SEARCH_API_KEY }}
CLOUDFRONT_KEY_GROUP_ID: ${{ secrets.CLOUDFRONT_KEY_GROUP_ID }}
: ${{ secrets. }}
APPLICATION_ENVIRONMENT: dev
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -87,7 +87,7 @@ jobs:
VERSION="${git_version}" pnpm --filter=@fern-platform/fdr-deploy deploy:dev
env:
DATABASE_URL: ${{ secrets.DEV_POSTGRES_URL }}/fdr?schema=public&connection_limit=6&pool_timeout=30
CLOUDFRONT_KEY_GROUP_ID: ${{ secrets.CLOUDFRONT_KEY_GROUP_ID }}
: ${{ secrets. }}

smoke-test:
needs: deploy_dev
Expand Down
4 changes: 4 additions & 0 deletions packages/fern-docs/bundle/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ const nextConfig = {
config.externals = config.externals || [];
config.externals.push("esbuild");
}
config.resolve.fallback = {
...config.resolve.fallback,
crypto: false,
};
config.module.rules.push({
test: /\.(glsl|vs|fs|vert|frag)$/,
exclude: /node_modules/,
Expand Down
3 changes: 3 additions & 0 deletions packages/fern-docs/bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"directory": "packages/fern-docs/bundle"
},
"sideEffects": false,
"browser": {
"crypto": false
},
"scripts": {
"depcheck": "depcheck",
"docs:build": "next build",
Expand Down
17 changes: 14 additions & 3 deletions packages/fern-docs/bundle/src/server/loadDocsDefinitionFromS3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,29 @@ export async function loadDocsDefinitionFromS3({
try {
const cleanDomain = domain.replace(/^https?:\/\//, "");
const dbDocsDefUrl = `${docsDefinitionUrl}/${getS3KeyForV1DocsDefinition(cleanDomain)}`;
const cloudfrontPrivateKey = process.env.CLOUDFRONT_PRIVATE_KEY;
const cloudfrontKeyPairId = process.env.CLOUDFRONT_KEY_PAIR_ID;

if (!cloudfrontPrivateKey) {
throw new Error("Missing required CLOUDFRONT_PRIVATE_KEY");
}
if (!cloudfrontKeyPairId) {
throw new Error("Missing required CLOUDFRONT_KEY_PAIR_ID");
}
const signedUrl = getSignedUrl({
url: dbDocsDefUrl,
privateKey: process.env.CLOUDFRONT_PRIVATE_KEY || "",
keyPairId: process.env.CLOUDFRONT_KEY_PAIR_ID || "",
privateKey: cloudfrontPrivateKey,
keyPairId: cloudfrontKeyPairId,
dateLessThan: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30).toString(),
});
const response = await fetch(signedUrl);
if (response.ok) {
const json = await response.json();
return json as FdrAPI.docs.v2.read.LoadDocsForUrlResponse;
}
return undefined;
throw new Error(
`Failed to load docs definition. Status: ${response.status}. Error: ${await response.text()}`
);
} catch (error) {
console.error("Error loading docs definition from S3:", error);
return undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/fern-docs/ui/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"NEXT_PUBLIC_VERCEL_ENV",
"NEXT_PUBLIC_DOCS_DEFINITION_S3_URL",
"CLOUDFRONT_PRIVATE_KEY",
"CLOUDFRONT_KEY_GROUP_ID"
"CLOUDFRONT_KEY_PAIR_ID"
],
"inputs": ["$TURBO_DEFAULT$"]
}
Expand Down
2 changes: 1 addition & 1 deletion servers/fdr-deploy/scripts/fdr-deploy-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class FdrDeployStack extends Stack {
}
);

const keyGroupId = getEnvironmentVariableOrThrow("CLOUDFRONT_KEY_GROUP_ID");
const keyGroupId = getEnvironmentVariableOrThrow("");
const dbDocsKeyGroup = cloudfront.KeyGroup.fromKeyGroupId(
this,
"DbDocsKeyGroup",
Expand Down

0 comments on commit cc98a4f

Please sign in to comment.