feat: migrate from lemonsqueezy to polar (#535)

* feat: move from lemonsqueezy to polar

* update lock

* add migration files

* test with demo product id
This commit is contained in:
Rotimi Best
2025-01-06 03:36:00 +01:00
committed by GitHub
parent 32ba251b77
commit de1398b3a2
14 changed files with 398 additions and 94 deletions
+25 -4
View File
@@ -21,6 +21,8 @@ interface LoadOutput {
serverLang: string;
}
const APP_SUBDOMAINS = env.PRIVATE_APP_SUBDOMAINS.split(',');
export const load = async ({ url, cookies, request }): Promise<LoadOutput> => {
const response: LoadOutput = {
orgSiteName: '',
@@ -31,6 +33,8 @@ export const load = async ({ url, cookies, request }): Promise<LoadOutput> => {
serverLang: request.headers?.get('accept-language') || ''
};
console.log('IS_SELFHOSTED', IS_SELFHOSTED);
// Selfhosted usecase would be here
if (IS_SELFHOSTED === 'true') {
const subdomain = getSubdomain(url);
@@ -72,7 +76,7 @@ export const load = async ({ url, cookies, request }): Promise<LoadOutput> => {
const isDev = dev || isLocalHost;
if (!url.host.includes('.classroomio.com') && !isLocalHost) {
if (isURLCustomDomain(url)) {
// Custom domain
response.org = (await getCurrentOrg(url.host, true, true)) || null;
@@ -86,8 +90,15 @@ export const load = async ({ url, cookies, request }): Promise<LoadOutput> => {
response.orgSiteName = response.org?.siteName || '';
return response;
} else if (!blockedSubdomain.includes(subdomain)) {
if (APP_SUBDOMAINS.includes(subdomain)) {
// This is an app domain specified in the .env file
return response;
}
const answer = !!subdomain;
console.log('subdomain', subdomain);
response.isOrgSite = debugMode || answer;
response.orgSiteName = debugMode ? _orgSiteName : subdomain;
response.org = (await getCurrentOrg(response.orgSiteName, true)) || null;
@@ -99,7 +110,7 @@ export const load = async ({ url, cookies, request }): Promise<LoadOutput> => {
}
} else if (subdomain === 'play' || debugPlay === 'true') {
response.skipAuth = true;
} else if (!env.PRIVATE_APP_SUBDOMAINS.split(',').includes(subdomain) && !isDev) {
} else if (!APP_SUBDOMAINS.includes(subdomain) && !isDev) {
// This case is for anything in our blockedSubdomains
throw redirect(307, 'https://app.classroomio.com');
}
@@ -107,6 +118,18 @@ export const load = async ({ url, cookies, request }): Promise<LoadOutput> => {
return response;
};
function isURLCustomDomain(url: URL) {
if (url.host.includes('localhost')) {
return false;
}
const notCustomDomainHosts = [env.PRIVATE_APP_HOST || '', 'classroomio.com', 'vercel.app'].filter(
Boolean
);
return !notCustomDomainHosts.some((host) => url.host.endsWith(host));
}
function getBaseMetaTags(url: URL) {
return Object.freeze({
title: 'ClassroomIO | The Open Source Learning Management System for Companies',
@@ -145,8 +168,6 @@ function getBaseMetaTags(url: URL) {
});
}
function getSubdomain(url: URL) {
const host = url.host.replace('www.', '');
const parts = host.split('.');