Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: optionally disable-customdomains #638

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .docker.env
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ REDIS_PASSWORD=
# Disable registration
DISALLOW_REGISTRATION=false

# Disable Custom Domain
DISALLOW_DOMAIN=false

# Disable anonymous link creation
DISALLOW_ANONYMOUS_LINKS=false

Expand Down
3 changes: 3 additions & 0 deletions .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ REDIS_PASSWORD=
# Disable registration
DISALLOW_REGISTRATION=false

# Disable Custom Domain
DISALLOW_DOMAIN=false

# Disable anonymous link creation
DISALLOW_ANONYMOUS_LINKS=false

Expand Down
11 changes: 8 additions & 3 deletions client/components/Features.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import styled from "styled-components";
import { Flex } from "reflexbox/styled-components";
import { DISALLOW_DOMAIN } from "../consts";

import FeaturesItem from "./FeaturesItem";
import { ColCenterH } from "./Layout";
Expand Down Expand Up @@ -28,9 +29,13 @@ const Features = () => (
Create, protect and delete your links and monitor them with detailed
statistics.
</FeaturesItem>
<FeaturesItem title="Custom domain" icon="shuffle">
Use custom domains for your links. Add or remove them for free.
</FeaturesItem>
{DISALLOW_DOMAIN && (
<>
<FeaturesItem title="Custom domain" icon="shuffle">
Use custom domains for your links. Add or remove them for free.
</FeaturesItem>
</>
)}
<FeaturesItem title="API" icon="zap">
Use the provided API to create, delete, and get URLs from anywhere.
</FeaturesItem>
Expand Down
3 changes: 2 additions & 1 deletion client/components/NeedToLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Flex } from "reflexbox/styled-components";
import { Button } from "./Button";
import { fadeIn } from "../helpers/animations";
import { Col } from "./Layout";
import { DISALLOW_DOMAIN } from "../consts";

const Wrapper = styled(Flex).attrs({
width: 1200,
Expand Down Expand Up @@ -63,7 +64,7 @@ const NeedToLogin = () => (
mb={[32, 32, 0]}
>
<Title>
Manage links, set custom <b>domains</b> and view <b>stats</b>.
Manage links{DISALLOW_DOMAIN && (<>, set custom <b>domains</b></>)} and view <b>stats</b>.
</Title>
<Link href="/login">
<a href="/login" title="login / signup">
Expand Down
3 changes: 3 additions & 0 deletions client/consts/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export const DISALLOW_ANONYMOUS_LINKS =

export const DISALLOW_REGISTRATION =
publicRuntimeConfig.DISALLOW_REGISTRATION === "true";

export const DISALLOW_DOMAIN =
publicRuntimeConfig.DISALLOW_DOMAIN === "true";

export enum API {
BAN_LINK = "/api/url/admin/ban",
Expand Down
5 changes: 3 additions & 2 deletions client/pages/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Divider from "../components/Divider";
import { Col } from "../components/Layout";
import Footer from "../components/Footer";
import { useStoreState } from "../store";
import { DISALLOW_DOMAIN } from "../consts";

const SettingsPage: NextPage = () => {
const email = useStoreState(s => s.auth.email);
Expand All @@ -26,8 +27,8 @@ const SettingsPage: NextPage = () => {
</Span>
.
</H1>
<Divider mt={4} mb={48} />
<SettingsDomain />
{!DISALLOW_DOMAIN && <Divider mt={4} mb={48} />}
{!DISALLOW_DOMAIN && <SettingsDomain />}
<Divider mt={4} mb={48} />
<SettingsApi />
<Divider mt={4} mb={48} />
Expand Down
3 changes: 2 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
REPORT_EMAIL: localEnv && localEnv.REPORT_EMAIL,
DISALLOW_ANONYMOUS_LINKS: localEnv && localEnv.DISALLOW_ANONYMOUS_LINKS,
DISALLOW_REGISTRATION: localEnv && localEnv.DISALLOW_REGISTRATION,
SENTRY_PUBLIC_DSN: localEnv && localEnv.SENTRY_PUBLIC_DSN,
DISALLOW_DOMAIN: localEnv && localEnv.DISALLOW_DOMAIN,
SENTRY_PUBLIC_DSN: localEnv && localEnv.SENTRY_PUBLIC_DSN
}
};
1 change: 1 addition & 0 deletions server/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const env = cleanEnv(process.env, {
NON_USER_COOLDOWN: num({ default: 10 }),
DEFAULT_MAX_STATS_PER_LINK: num({ default: 5000 }),
DISALLOW_ANONYMOUS_LINKS: bool({ default: false }),
DISALLOW_DOMAIN: bool({ default: false }),
DISALLOW_REGISTRATION: bool({ default: false }),
CUSTOM_DOMAIN_USE_HTTPS: bool({ default: false }),
JWT_SECRET: str(),
Expand Down
4 changes: 4 additions & 0 deletions server/handlers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,7 @@ export const changeEmail: Handler = async (req, res, next) => {
}
return next();
};

export const bypass: Handler = async (req, res, next) => {
return next();
};
3 changes: 3 additions & 0 deletions server/routes/domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import * as validators from "../handlers/validators";
import * as helpers from "../handlers/helpers";
import * as domains from "../handlers/domains";
import * as auth from "../handlers/auth";
import env from "../env";

const router = Router();

router.post(
"/",
asyncHandler(auth.apikey),
asyncHandler(auth.jwt),
asyncHandler(env.DISALLOW_DOMAIN ? auth.admin : auth.bypass),
validators.addDomain,
asyncHandler(helpers.verify),
asyncHandler(domains.add)
Expand All @@ -21,6 +23,7 @@ router.delete(
"/:id",
asyncHandler(auth.apikey),
asyncHandler(auth.jwt),
asyncHandler(env.DISALLOW_DOMAIN ? auth.admin : auth.bypass),
validators.removeDomain,
asyncHandler(helpers.verify),
asyncHandler(domains.remove)
Expand Down