Skip to content

Commit

Permalink
Merge pull request #193 from midday-ai/feature/engine-v1.1
Browse files Browse the repository at this point in the history
Feature/engine v1.1
  • Loading branch information
pontusab authored Jul 12, 2024
2 parents a553992 + a9b1093 commit a2e8b3e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 25 deletions.
14 changes: 10 additions & 4 deletions apps/engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ app.use(

return bearer(c, next);
},
(c, next) => {
if (PUBLIC_PATHS.includes(c.req.path)) {
return next();
}

return cache({
cacheName: "engine",
cacheControl: "max-age=3600",
})(c, next);
},
secureHeaders(),
logger(customLogger),
cache({
cacheName: "engine",
cacheControl: "max-age=3600",
}),
);

app
Expand Down
20 changes: 17 additions & 3 deletions apps/engine/src/routes/health/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Bindings } from "@/common/bindings";
import { ErrorSchema } from "@/common/schema";
import { Provider } from "@/providers";
import { SearchClient } from "@/utils/search";
import { createRoute } from "@hono/zod-openapi";
import { OpenAPIHono } from "@hono/zod-openapi";
import { env } from "hono/adapter";
Expand Down Expand Up @@ -37,18 +38,31 @@ app.openapi(indexRoute, async (c) => {

const api = new Provider();

const data = await api.getHealthCheck({
const providers = await api.getHealthCheck({
kv: c.env.KV,
fetcher: c.env.TELLER_CERT,
envs,
});

const isHealthy = Object.values(data).every((service) => service.healthy);
const typesense = SearchClient(envs);
const searchResponse = await typesense.health.retrieve();

const allServices = {
...providers,
search: {
healthy:
typeof searchResponse === "string" && JSON.parse(searchResponse).ok,
},
};

const isHealthy = Object.values(allServices).every(
(service) => service.healthy,
);

if (isHealthy) {
return c.json(
{
data,
data: allServices,
},
200,
);
Expand Down
17 changes: 2 additions & 15 deletions apps/engine/src/routes/institutions/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Bindings } from "@/common/bindings";
import { ErrorSchema } from "@/common/schema";
import type { Providers } from "@/providers/types";
import { SearchClient } from "@/utils/search";
import { createRoute } from "@hono/zod-openapi";
import { OpenAPIHono } from "@hono/zod-openapi";
import { env } from "hono/adapter";
import Typesense from "typesense";
import { InstitutionParamsSchema, InstitutionsSchema } from "./schema";

const app = new OpenAPIHono<{ Bindings: Bindings }>();
Expand Down Expand Up @@ -52,20 +52,7 @@ app.openapi(indexRoute, async (c) => {
const envs = env(c);
const { countryCode, q = "*", limit = "50" } = c.req.valid("query");

const typesense = new Typesense.Client({
nearestNode: {
host: envs.TYPESENSE_ENDPOINT!,
port: 443,
protocol: "https",
},
nodes: [
{ host: envs.TYPESENSE_ENDPOINT_US!, port: 443, protocol: "https" },
{ host: envs.TYPESENSE_ENDPOINT_EU!, port: 443, protocol: "https" },
{ host: envs.TYPESENSE_ENDPOINT_AU!, port: 443, protocol: "https" },
],
apiKey: envs.TYPESENSE_API_KEY,
connectionTimeoutSeconds: 2,
});
const typesense = SearchClient(envs);

const searchParameters = {
q,
Expand Down
19 changes: 19 additions & 0 deletions apps/engine/src/utils/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Bindings } from "@/common/bindings";
import Typesense from "typesense";

export function SearchClient(envs: Bindings) {
return new Typesense.Client({
nearestNode: {
host: envs.TYPESENSE_ENDPOINT!,
port: 443,
protocol: "https",
},
nodes: [
{ host: envs.TYPESENSE_ENDPOINT_US!, port: 443, protocol: "https" },
{ host: envs.TYPESENSE_ENDPOINT_EU!, port: 443, protocol: "https" },
{ host: envs.TYPESENSE_ENDPOINT_AU!, port: 443, protocol: "https" },
],
apiKey: envs.TYPESENSE_API_KEY,
connectionTimeoutSeconds: 2,
});
}
4 changes: 2 additions & 2 deletions apps/engine/tasks/get-institutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ export async function getPlaidInstitutions() {

export async function getInstitutions() {
const data = await Promise.all([
// getGoCardLessInstitutions(),
// getTellerInstitutions(),
getGoCardLessInstitutions(),
getTellerInstitutions(),
getPlaidInstitutions(),
]);

Expand Down
2 changes: 1 addition & 1 deletion apps/engine/tasks/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const typesense = new Typesense.Client({
protocol: "https",
},
],
apiKey: process.env.TYPESENSE_ADMIN_KEY!,
apiKey: process.env.TYPESENSE_API_KEY!,
numRetries: 3,
connectionTimeoutSeconds: 120,
logLevel: "debug",
Expand Down

0 comments on commit a2e8b3e

Please sign in to comment.