refactor: make app portable for open source
- Remove hardcoded api.manoonoils.com fetch patch - Make allowedSaleorUrls configurable via ALLOWED_SALEOR_URLS env var - Make email logo/company configurable via EMAIL_LOGO_URL, EMAIL_COMPANY_NAME - Add comprehensive README with deployment docs - Keep internal networking preference via SALEOR_API_URL env var
This commit is contained in:
+31
-19
@@ -21,25 +21,35 @@ interface BaseLayoutProps {
|
||||
|
||||
const translations: Record<string, { footer: string; company: string }> = {
|
||||
sr: {
|
||||
footer: "ManoonOils - Prirodna kozmetika | www.manoonoils.com",
|
||||
company: "ManoonOils",
|
||||
footer: "",
|
||||
company: "",
|
||||
},
|
||||
en: {
|
||||
footer: "ManoonOils - Natural Cosmetics | www.manoonoils.com",
|
||||
company: "ManoonOils",
|
||||
footer: "",
|
||||
company: "",
|
||||
},
|
||||
de: {
|
||||
footer: "ManoonOils - Natürliche Kosmetik | www.manoonoils.com",
|
||||
company: "ManoonOils",
|
||||
footer: "",
|
||||
company: "",
|
||||
},
|
||||
fr: {
|
||||
footer: "ManoonOils - Cosmétiques Naturels | www.manoonoils.com",
|
||||
company: "ManoonOils",
|
||||
footer: "",
|
||||
company: "",
|
||||
},
|
||||
};
|
||||
|
||||
export function BaseLayout({ children, previewText, language, siteUrl }: BaseLayoutProps) {
|
||||
const COMPANY_NAME = process.env.EMAIL_COMPANY_NAME || "Store";
|
||||
const LOGO_URL = process.env.EMAIL_LOGO_URL || "";
|
||||
const DEFAULT_FOOTER = process.env.EMAIL_FOOTER || `${COMPANY_NAME} | ${process.env.SITE_URL || ""}`;
|
||||
|
||||
function getFooter(language: string): string {
|
||||
const t = translations[language] || translations.en;
|
||||
const footer = t.footer || DEFAULT_FOOTER;
|
||||
return footer.replace("{company}", COMPANY_NAME).replace("{siteUrl}", process.env.SITE_URL || "");
|
||||
}
|
||||
|
||||
export function BaseLayout({ children, previewText, language, siteUrl }: BaseLayoutProps) {
|
||||
const footer = getFooter(language);
|
||||
|
||||
return (
|
||||
<Html>
|
||||
@@ -47,18 +57,20 @@ export function BaseLayout({ children, previewText, language, siteUrl }: BaseLay
|
||||
<Preview>{previewText}</Preview>
|
||||
<Body style={styles.body}>
|
||||
<Container style={styles.container}>
|
||||
<Section style={styles.logoSection}>
|
||||
<Img
|
||||
src="https://minio-api.nodecrew.me/manoon-media/2024/09/cropped-manoon-logo_256x-1-1.png"
|
||||
width="150"
|
||||
height="auto"
|
||||
alt="ManoonOils"
|
||||
style={styles.logo}
|
||||
/>
|
||||
</Section>
|
||||
{LOGO_URL && (
|
||||
<Section style={styles.logoSection}>
|
||||
<Img
|
||||
src={LOGO_URL}
|
||||
width="150"
|
||||
height="auto"
|
||||
alt={COMPANY_NAME}
|
||||
style={styles.logo}
|
||||
/>
|
||||
</Section>
|
||||
)}
|
||||
{children}
|
||||
<Section style={styles.footer}>
|
||||
<Text style={styles.footerText}>{t.footer}</Text>
|
||||
<Text style={styles.footerText}>{footer}</Text>
|
||||
</Section>
|
||||
</Container>
|
||||
</Body>
|
||||
|
||||
@@ -1,21 +1,11 @@
|
||||
// Patch fetch to force HTTPS for api.manoonoils.com
|
||||
const originalFetch = global.fetch;
|
||||
global.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
let url = input.toString();
|
||||
if (url.startsWith('http://api.manoonoils.com/')) {
|
||||
url = url.replace('http://', 'https://');
|
||||
input = url;
|
||||
}
|
||||
return originalFetch(input, init);
|
||||
};
|
||||
|
||||
import { createAppRegisterHandler } from "@saleor/app-sdk/handlers/next";
|
||||
import { saleorApp } from "@/saleor-app";
|
||||
|
||||
const allowedSaleorUrls = process.env.ALLOWED_SALEOR_URLS
|
||||
? process.env.ALLOWED_SALEOR_URLS.split(",").map((url) => url.trim())
|
||||
: ["http://localhost:3000", "https://*.saleor.cloud"];
|
||||
|
||||
export default createAppRegisterHandler({
|
||||
apl: saleorApp.apl,
|
||||
allowedSaleorUrls: [
|
||||
"https://api.manoonoils.com/graphql/",
|
||||
"http://api.manoonoils.com/graphql/",
|
||||
],
|
||||
allowedSaleorUrls,
|
||||
});
|
||||
Reference in New Issue
Block a user