Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/compute/cloud/common/dns.tsx
Views: 687
import { DNS_COST_PER_HOUR, checkValidDomain } from "@cocalc/util/compute/dns";1import { useTypedRedux } from "@cocalc/frontend/app-framework";2import { useEffect, useState } from "react";3import { Button, Checkbox, Input, Typography } from "antd";4import { A, Icon } from "@cocalc/frontend/components";5import { currency } from "@cocalc/util/misc";67export default function DNS({ setConfig, configuration, loading }) {8const compute_servers_dns = useTypedRedux("customize", "compute_servers_dns");9const [showDns, setShowDns] = useState<boolean>(!!configuration.dns);10const [dnsError, setDnsError] = useState<string>("");11const [dns, setDns] = useState<string | undefined>(configuration.dns);12useEffect(() => {13if (!dns) return;14try {15checkValidDomain(dns);16setDnsError("");17} catch (err) {18setDnsError(`${err}`);19}20}, [dns]);2122if (!compute_servers_dns) {23return null;24}2526return (27<div>28<Checkbox29disabled={loading}30checked={showDns}31onChange={() => {32setShowDns(!showDns);33if (showDns) {34// disable on backend.35setConfig({ dns: "" });36}37}}38>39DNS: Custom Subdomain with SSL ({currency(DNS_COST_PER_HOUR)}/hour when40running or stopped)41</Checkbox>42{showDns && (43<A44style={{ float: "right" }}45href={`https://${configuration.dns}.${compute_servers_dns}`}46>47<Icon name="external-link" /> https://{dns ?? "*"}.48{compute_servers_dns}49</A>50)}51{showDns && (52<div style={{ marginTop: "5px" }}>53<Input54disabled={loading}55style={{ margin: "15px 0" }}56maxLength={63}57showCount58allowClear59value={dns}60onChange={(e) => {61const dns = e.target.value.trim();62setDns(dns);63if (!dns) {64setConfig({ dns: "" });65}66}}67/>6869<Button70disabled={configuration.dns == dns || dnsError || loading}71onClick={() => {72const s = (dns ?? "").toLowerCase();73setConfig({ dns: s });74setDns(s);75}}76>77{!dns || configuration.dns != dns78? "Enable Custom Domain"79: "Custom Domain Enabled"}80</Button>81<div style={{ color: "#666", margin: "5px 0" }}>82<Typography.Paragraph83style={{ color: "#666" }}84ellipsis={{85expandable: true,86rows: 2,87symbol: "more",88}}89>90A custom DNS A record with{" "}91<A href="https://developers.cloudflare.com/dns/manage-dns-records/reference/proxied-dns-records/">92https and http proxying will be created at CloudFlare93</A>{" "}94as long as your VM is not deprovisioned. Whenever your VM starts95running it is allocated an external ip address, and CoCalc updates96the DNS entry to point at that ip address. A web server with97self-signed certificate will appear to have a proper certificate98to website visitors. You can enable or disable custom DNS at any99time.100</Typography.Paragraph>101</div>102{dnsError && dns && (103<div104style={{105background: "red",106color: "white",107padding: "5px",108margin: "10px 0",109}}110>111<div>{dnsError}</div>112Please enter a valid subdomain name. Subdomains can consist of113letters (a-z, A-Z), numbers (0-9), and hyphens (-). They cannot114start or end with a hyphen.115</div>116)}117</div>118)}119</div>120);121}122123124