diff --git a/.docker.env b/.docker.env index 740be822f..148cdc8b9 100644 --- a/.docker.env +++ b/.docker.env @@ -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 diff --git a/.example.env b/.example.env index 634af8e6a..f748a21aa 100644 --- a/.example.env +++ b/.example.env @@ -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 diff --git a/client/components/Features.tsx b/client/components/Features.tsx index 2a6d450ec..07dd081ec 100644 --- a/client/components/Features.tsx +++ b/client/components/Features.tsx @@ -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"; @@ -28,9 +29,13 @@ const Features = () => ( Create, protect and delete your links and monitor them with detailed statistics. - - Use custom domains for your links. Add or remove them for free. - + {DISALLOW_DOMAIN && ( + <> + + Use custom domains for your links. Add or remove them for free. + + + )} Use the provided API to create, delete, and get URLs from anywhere. diff --git a/client/components/NeedToLogin.tsx b/client/components/NeedToLogin.tsx index c2e8c5675..8d9e84f51 100644 --- a/client/components/NeedToLogin.tsx +++ b/client/components/NeedToLogin.tsx @@ -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, @@ -63,7 +64,7 @@ const NeedToLogin = () => ( mb={[32, 32, 0]} > - 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>. diff --git a/client/consts/consts.ts b/client/consts/consts.ts index bd440eaca..2acce0dd3 100644 --- a/client/consts/consts.ts +++ b/client/consts/consts.ts @@ -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", diff --git a/client/pages/settings.tsx b/client/pages/settings.tsx index 2d6bdb0d7..12457b604 100644 --- a/client/pages/settings.tsx +++ b/client/pages/settings.tsx @@ -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); @@ -26,8 +27,8 @@ const SettingsPage: NextPage = () => { . - - + {!DISALLOW_DOMAIN && } + {!DISALLOW_DOMAIN && } diff --git a/next.config.js b/next.config.js index 738db8eee..0dd94fb8f 100644 --- a/next.config.js +++ b/next.config.js @@ -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 } }; diff --git a/server/env.ts b/server/env.ts index 4f0d75ff1..e1c009fa7 100644 --- a/server/env.ts +++ b/server/env.ts @@ -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(), diff --git a/server/handlers/auth.ts b/server/handlers/auth.ts index a1431bd82..8fd425264 100644 --- a/server/handlers/auth.ts +++ b/server/handlers/auth.ts @@ -294,3 +294,7 @@ export const changeEmail: Handler = async (req, res, next) => { } return next(); }; + +export const bypass: Handler = async (req, res, next) => { + return next(); +}; diff --git a/server/routes/domains.ts b/server/routes/domains.ts index 2a06e633e..b6dc8092f 100644 --- a/server/routes/domains.ts +++ b/server/routes/domains.ts @@ -5,6 +5,7 @@ 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(); @@ -12,6 +13,7 @@ router.post( "/", asyncHandler(auth.apikey), asyncHandler(auth.jwt), + asyncHandler(env.DISALLOW_DOMAIN ? auth.admin : auth.bypass), validators.addDomain, asyncHandler(helpers.verify), asyncHandler(domains.add) @@ -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)