diff --git a/.example.env b/.example.env index f739887d0..b105cd17d 100644 --- a/.example.env +++ b/.example.env @@ -7,6 +7,9 @@ SITE_NAME=Kutt # The domain that this website is on DEFAULT_DOMAIN=localhost:3000 +# false for development use, true for production use when serving on https +DEFAULT_DOMAIN_HTTPS=false + # Generated link length LINK_LENGTH=6 diff --git a/server/env.ts b/server/env.ts index 075178c01..e51a3573a 100644 --- a/server/env.ts +++ b/server/env.ts @@ -7,6 +7,7 @@ const env = cleanEnv(process.env, { PORT: num({ default: 3000 }), SITE_NAME: str({ example: "Kutt" }), DEFAULT_DOMAIN: str({ example: "kutt.it" }), + DEFAULT_DOMAIN_HTTPS: bool({ default: false }), LINK_LENGTH: num({ default: 6 }), DB_HOST: str({ default: "localhost" }), DB_PORT: num({ default: 5432 }), diff --git a/server/handlers/links.ts b/server/handlers/links.ts index 5134cd0d1..cf579ea84 100644 --- a/server/handlers/links.ts +++ b/server/handlers/links.ts @@ -360,9 +360,10 @@ export const redirectCustomDomain: Handler = async (req, res, next) => { .some(item => item === path.replace("/", "")) ) { const domain = await query.domain.find({ address: host }); + const protocol = env.DEFAULT_DOMAIN_HTTPS ? 'https' : 'http'; const redirectURL = domain ? domain.homepage - : `https://${env.DEFAULT_DOMAIN + path}`; + : `${protocol}://${env.DEFAULT_DOMAIN + path}`; return res.redirect(302, redirectURL); } diff --git a/server/utils/index.ts b/server/utils/index.ts index cda1956b5..94bd3ad1b 100644 --- a/server/utils/index.ts +++ b/server/utils/index.ts @@ -57,7 +57,7 @@ export const addProtocol = (url: string): string => { export const generateShortLink = (id: string, domain?: string): string => { const protocol = - env.CUSTOM_DOMAIN_USE_HTTPS || !domain ? "https://" : "http://"; + env.CUSTOM_DOMAIN_USE_HTTPS || env.DEFAULT_DOMAIN_HTTPS ? "https://" : "http://"; return `${protocol}${domain || env.DEFAULT_DOMAIN}/${id}`; };