diff --git a/sites/partners/src/logger.ts b/sites/partners/src/logger.ts index 5f094b710e..3361fde754 100644 --- a/sites/partners/src/logger.ts +++ b/sites/partners/src/logger.ts @@ -1,8 +1,10 @@ import * as winston from "winston" + let log_level = "info" if (process.env.LOG_LEVEL) { log_level = process.env.LOG_LEVEL } + const logger = winston.createLogger({ level: log_level, format: winston.format.json(), diff --git a/sites/partners/src/pages/api/adapter/[...backendUrl].ts b/sites/partners/src/pages/api/adapter/[...backendUrl].ts index 9e3ca1cb06..942518efad 100644 --- a/sites/partners/src/pages/api/adapter/[...backendUrl].ts +++ b/sites/partners/src/pages/api/adapter/[...backendUrl].ts @@ -4,7 +4,6 @@ import qs from "qs" import { wrapper } from "axios-cookiejar-support" import { CookieJar } from "tough-cookie" import { getConfigs } from "@bloom-housing/shared-helpers/src/types/backend-swagger" -import { maskAxiosResponse } from "@bloom-housing/shared-helpers" import { logger } from "../../../logger" /* @@ -33,16 +32,15 @@ export default async (req: NextApiRequest, res: NextApiResponse) => { jar, }) ) - // set up request to backend from request to next api + // eslint-disable-next-line prefer-const let { backendUrl, ...rest } = req.query - logger.info(`${req.method} - ${backendUrl}`) - logger.debug(req) - if (Array.isArray(backendUrl)) { backendUrl = backendUrl.join("/") } + try { + // set up request to backend from request to next api const configs = getConfigs(req.method || "", "application/json", backendUrl || "", {}) let cookieString = "" Object.keys(req.cookies).forEach((cookieHeader) => { @@ -52,6 +50,10 @@ export default async (req: NextApiRequest, res: NextApiResponse) => { configs.params = rest configs.data = req.body || {} + // log that call is going out + logger.info(`${req.method} - ${backendUrl}`) + logger.debug(req) + // send request to backend // the zip endpoints also require a responseType of arraybuffer const response = await axios.request({ @@ -85,7 +87,7 @@ export default async (req: NextApiRequest, res: NextApiResponse) => { res.statusMessage = e.response.statusText res.status(e.response.status).json(e.response.data) } else { - logger.error("public backend url adapter error:", e) + logger.error("partner backend url adapter error:", e) } } } diff --git a/sites/partners/src/pages/listings/[id]/edit.tsx b/sites/partners/src/pages/listings/[id]/edit.tsx index ac496e4734..8ad9d1ebbe 100644 --- a/sites/partners/src/pages/listings/[id]/edit.tsx +++ b/sites/partners/src/pages/listings/[id]/edit.tsx @@ -10,6 +10,7 @@ import { MetaTags } from "../../../components/shared/MetaTags" import ListingGuard from "../../../components/shared/ListingGuard" import { NavigationHeader } from "../../../components/shared/NavigationHeader" import { FormListing } from "../../../lib/listings/formTypes" +import { logger } from "../../../logger" const EditListing = (props: { listing: Listing }) => { const metaDescription = "" @@ -63,11 +64,17 @@ const EditListing = (props: { listing: Listing }) => { export async function getServerSideProps(context: { params: Record }) { let response + const backendUrl = `/listings/${context.params.id}` try { - response = await axios.get(`${process.env.backendApiBase}/listings/${context.params.id}`) + logger.info(`GET - ${backendUrl}`) + response = await axios.get(`${process.env.backendApiBase}${backendUrl}`) } catch (e) { - console.log("e = ", e) + if (e.response) { + logger.error(`GET - ${backendUrl} - ${e.response?.status} - ${e.response?.statusText}`) + } else { + logger.error("partner backend url adapter error:", e) + } return { notFound: true } } diff --git a/sites/partners/src/pages/listings/[id]/index.tsx b/sites/partners/src/pages/listings/[id]/index.tsx index d6f699d62d..e6ad769049 100644 --- a/sites/partners/src/pages/listings/[id]/index.tsx +++ b/sites/partners/src/pages/listings/[id]/index.tsx @@ -35,6 +35,7 @@ import DetailPreferences from "../../../components/listings/PaperListingDetails/ import DetailCommunityType from "../../../components/listings/PaperListingDetails/sections/DetailCommunityType" import DetailPrograms from "../../../components/listings/PaperListingDetails/sections/DetailPrograms" import DetailListingNotes from "../../../components/listings/PaperListingDetails/sections/DetailNotes" +import { logger } from "../../../logger" interface ListingProps { listing: Listing @@ -129,10 +130,17 @@ export default function ListingDetail(props: ListingProps) { export async function getServerSideProps(context: { params: Record }) { let response + const backendUrl = `/listings/${context.params.id}` try { - response = await axios.get(`${process.env.backendApiBase}/listings/${context.params.id}`) + logger.info(`GET - ${backendUrl}`) + response = await axios.get(`${process.env.backendApiBase}${backendUrl}`) } catch (e) { + if (e.response) { + logger.error(`GET - ${backendUrl} - ${e.response?.status} - ${e.response?.statusText}`) + } else { + logger.error("partner backend url adapter error:", e) + } return { notFound: true } } diff --git a/sites/public/src/logger.ts b/sites/public/src/logger.ts new file mode 100644 index 0000000000..ab02d2ca7b --- /dev/null +++ b/sites/public/src/logger.ts @@ -0,0 +1,12 @@ +import * as winston from "winston" +let log_level = "info" +if (process.env.LOG_LEVEL) { + log_level = process.env.LOG_LEVEL +} +const logger = winston.createLogger({ + level: log_level, + format: winston.format.json(), + defaultMeta: { service: "doorway-public" }, + transports: [new winston.transports.Console()], +}) +export { logger } diff --git a/sites/public/src/pages/api/adapter/[...backendUrl].ts b/sites/public/src/pages/api/adapter/[...backendUrl].ts index 22c5e0cd93..c5f665725a 100644 --- a/sites/public/src/pages/api/adapter/[...backendUrl].ts +++ b/sites/public/src/pages/api/adapter/[...backendUrl].ts @@ -4,8 +4,7 @@ import qs from "qs" import { wrapper } from "axios-cookiejar-support" import { CookieJar } from "tough-cookie" import { getConfigs } from "@bloom-housing/shared-helpers/src/types/backend-swagger" -import { maskAxiosResponse } from "@bloom-housing/shared-helpers" -import { logger } from "../../../../logger" +import { logger } from "../../../logger" /* This file exists as per https://nextjs.org/docs/api-routes/dynamic-api-routes @@ -30,16 +29,15 @@ export default async (req: NextApiRequest, res: NextApiResponse) => { jar, }) ) - // set up request to backend from request to next api + // eslint-disable-next-line prefer-const let { backendUrl, ...rest } = req.query - logger.info(`${req.method} - ${backendUrl}`) - logger.debug(req) - if (Array.isArray(backendUrl)) { backendUrl = backendUrl.join("/") } + try { + // set up request to backend from request to next api const configs = getConfigs(req.method || "", "application/json", backendUrl || "", {}) let cookieString = "" Object.keys(req.cookies).forEach((cookieHeader) => { @@ -49,6 +47,10 @@ export default async (req: NextApiRequest, res: NextApiResponse) => { configs.params = rest configs.data = req.body || {} + // log that call is going out + logger.info(`${req.method} - ${backendUrl}`) + logger.debug(req) + // send request to backend const response = await axios.request(configs)