added axios client

This commit is contained in:
Milo Schwartz
2024-10-06 12:39:05 -04:00
parent 3c69acaab7
commit 29777da430
7 changed files with 81 additions and 41 deletions

View File

@@ -43,7 +43,17 @@ const environmentSchema = z.object({
.pipe(z.number().optional()),
EMAIL_SMTP_USER: z.string().optional(),
EMAIL_SMTP_PASS: z.string().optional(),
EMAIL_NOREPLY: z.string().optional(),
EMAIL_NOREPLY: z.string().email().optional(),
SITE_DOMAIN: z
.string()
.optional()
.transform((val) => {
if (!val) {
return `http://localhost:${environment.EXTERNAL_PORT}`;
}
return val;
})
.pipe(z.string().url()),
});
const environment = {
@@ -63,6 +73,7 @@ const environment = {
EMAIL_SMTP_USER: process.env.EMAIL_SMTP_USER as string,
EMAIL_SMTP_PASS: process.env.EMAIL_SMTP_PASS as string,
EMAIL_NOREPLY: process.env.EMAIL_NOREPLY as string,
SITE_DOMAIN: process.env.NEXT_PUBLIC_SITE_DOMAIN as string,
};
const parsedConfig = environmentSchema.safeParse(environment);

View File

@@ -7,6 +7,7 @@ import helmet from "helmet";
import cors from "cors";
import {
errorHandlerMiddleware,
notFoundMiddleware,
rateLimitMiddleware,
} from "@server/middlewares";
import internal from "@server/routers/internal";
@@ -42,6 +43,8 @@ app.prepare().then(() => {
externalServer.use(prefix, unauthenticated);
externalServer.use(prefix, authenticated);
externalServer.use(notFoundMiddleware)
// We are using NEXT from here on
externalServer.all("*", (req: Request, res: Response) => {
const parsedUrl = parse(req.url!, true);

View File

@@ -7,8 +7,11 @@ export function notFoundMiddleware(
res: Response,
next: NextFunction,
) {
const message = `The requests url is not found - ${req.originalUrl}`;
return next(createHttpError(HttpCode.NOT_FOUND, message));
if (req.path.startsWith("/api")) {
const message = `The requests url is not found - ${req.originalUrl}`;
return next(createHttpError(HttpCode.NOT_FOUND, message));
}
return next();
}
export default notFoundMiddleware;