Skip to content

Commit

Permalink
a fix for issue thedevs-network#735 to support http short links on de…
Browse files Browse the repository at this point in the history
…velopment mode
  • Loading branch information
jaysnm committed Mar 21, 2024
1 parent 041aed5 commit 136fe40
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions server/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down
3 changes: 2 additions & 1 deletion server/handlers/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion server/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
};

Expand Down

0 comments on commit 136fe40

Please sign in to comment.