Skip to content

Commit

Permalink
(chore): use ParsedBaseUrl.ts instead of getParsedUrl.ts (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Apr 16, 2024
1 parent 7a2b8d7 commit 1eba2ad
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
14 changes: 14 additions & 0 deletions servers/fdr/src/__test__/unit-tests/ParsedBaseUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,18 @@ describe("ParsedBaseUrl", () => {
expect(parsedUrl.path).toEqual("/docs");
expect(parsedUrl.getFullUrl()).toEqual("buildwithfern.com/docs");
});

it("apidocs.polytomic.com", () => {
const parsedUrl = ParsedBaseUrl.parse("apidocs.polytomic.com");
expect(parsedUrl.hostname).toEqual("apidocs.polytomic.com");
expect(parsedUrl.path).toEqual(undefined);
expect(parsedUrl.toURL()).toEqual(new URL("https://apidocs.polytomic.com"));
});

it("polytomic.docs.buildwithfern.com", () => {
const parsedUrl = ParsedBaseUrl.parse("polytomic.docs.buildwithfern.com");
expect(parsedUrl.hostname).toEqual("polytomic.docs.buildwithfern.com");
expect(parsedUrl.path).toEqual(undefined);
expect(parsedUrl.toURL()).toEqual(new URL("https://polytomic.docs.buildwithfern.com"));
});
});
14 changes: 7 additions & 7 deletions servers/fdr/src/controllers/docs/v2/getDocsReadV2Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { convertDbAPIDefinitionsToRead, convertDbDocsConfigToRead } from "@fern-
import NodeCache from "node-cache";
import { DocsV2Read, DocsV2ReadService } from "../../../api";
import type { FdrApplication } from "../../../app";
import { getParsedUrl } from "../../../util";
import { ParsedBaseUrl } from "../../../util/ParsedBaseUrl";

const SECONDS_IN_ONE_HOUR = 60 * 60;

Expand All @@ -14,21 +14,21 @@ const DOCS_CONFIG_ID_CACHE = new NodeCache({
export function getDocsReadV2Service(app: FdrApplication): DocsV2ReadService {
return new DocsV2ReadService({
getDocsForUrl: async (req, res) => {
const parsedUrl = getParsedUrl(req.body.url);
const response = await app.docsDefinitionCache.getDocsForUrl({ url: parsedUrl });
const parsedUrl = ParsedBaseUrl.parse(req.body.url);
const response = await app.docsDefinitionCache.getDocsForUrl({ url: parsedUrl.toURL() });
return res.send(response);
},
getPrivateDocsForUrl: async (req, res) => {
const parsedUrl = getParsedUrl(req.body.url);
const parsedUrl = ParsedBaseUrl.parse(req.body.url);
const response = await app.docsDefinitionCache.getDocsForUrl({
url: parsedUrl,
url: parsedUrl.toURL(),
authorization: req.headers.authorization,
});
return res.send(response);
},
getOrganizationForUrl: async (req, res) => {
const parsedUrl = getParsedUrl(req.body.url);
const orgId = await app.docsDefinitionCache.getOrganizationForUrl(parsedUrl);
const parsedUrl = ParsedBaseUrl.parse(req.body.url);
const orgId = await app.docsDefinitionCache.getOrganizationForUrl(parsedUrl.toURL());
if (orgId == null) {
throw new DocsV2Read.DomainNotRegisteredError();
}
Expand Down
8 changes: 0 additions & 8 deletions servers/fdr/src/util/getParsedUrl.ts

This file was deleted.

1 change: 0 additions & 1 deletion servers/fdr/src/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export type { WithoutQuestionMarks } from "./WithoutQuestionMarks";
export { assertNever, assertNeverNoThrow } from "./assertNever";
export { truncateToBytes } from "./bytes";
export { getParsedUrl } from "./getParsedUrl";
export { convertMarkdownToText } from "./markdown";
export { readBuffer, writeBuffer } from "./serde";

0 comments on commit 1eba2ad

Please sign in to comment.