Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

feat(phase5): add PrivateURLSection frontend component

Juan Denisf090f2bfe0c2
diff --git a/frontend/src/components/PrivateURLSection.jsx b/frontend/src/components/PrivateURLSection.jsx
new file mode 100644
index 00000000..ea232f68
--- /dev/null
+++ b/frontend/src/components/PrivateURLSection.jsx
@@ -0,0 +1,223 @@
+import React, { useState } from 'react';
+import api from '../services/api';
+import { useToast } from '../contexts/ToastContext';
+
+const PrivateURLSection = ({ app, onUpdate }) => {
+ const toast = useToast();
+ const [loading, setLoading] = useState(false);
+ const [customSlug, setCustomSlug] = useState('');
+ const [editMode, setEditMode] = useState(false);
+
+ const baseUrl = window.location.origin;
+ const privateUrl = app.private_slug ? `${baseUrl}/p/${app.private_slug}` : null;
+
+ async function handleEnable(e) {
+ e?.preventDefault();
+ setLoading(true);
+ try {
+ await api.enablePrivateUrl(app.id, customSlug || undefined);
+ toast.success('Private URL enabled');
+ onUpdate();
+ setCustomSlug('');
+ } catch (error) {
+ toast.error(error.message || 'Failed to enable private URL');
+ } finally {
+ setLoading(false);
+ }
+ }
+
+ async function handleDisable() {
+ if (!confirm('Disable private URL? The current slug will be released.')) return;
+
+ setLoading(true);
+ try {
+ await api.disablePrivateUrl(app.id);
+ toast.success('Private URL disabled');
+ onUpdate();
+ } catch (error) {
+ toast.error(error.message || 'Failed to disable private URL');
+ } finally {
+ setLoading(false);
+ }
+ }
+
+ async function handleRegenerate() {
+ if (!confirm('Generate a new random slug? The old URL will stop working.')) return;
+
+ setLoading(true);
+ try {
+ await api.regeneratePrivateUrl(app.id);
+ toast.success('Private URL regenerated');
+ onUpdate();
+ } catch (error) {
+ toast.error(error.message || 'Failed to regenerate');
+ } finally {
+ setLoading(false);
+ }
+ }
+
+ async function handleUpdateSlug(e) {
+ e?.preventDefault();
+ if (!customSlug) return;
+
+ setLoading(true);
+ try {
+ await api.updatePrivateUrl(app.id, customSlug);
+ toast.success('Slug updated');
+ onUpdate();
+ setEditMode(false);
+ setCustomSlug('');
+ } catch (error) {
+ toast.error(error.message || 'Failed to update slug');
+ } finally {
+ setLoading(false);
+ }
+ }
+
+ function copyToClipboard() {
+ navigator.clipboard.writeText(privateUrl);
+ toast.success('URL copied to clipboard');
+ }
+
+ function handleSlugInput(e) {
+ // Only allow lowercase letters, numbers, and hyphens
+ const value = e.target.value.toLowerCase().replace(/[^a-z0-9-]/g, '');
+ setCustomSlug(value);
+ }
+
+ return (
+ <div className="private-url-section">
+ <div className="section-header">
+ <h3>
+ <svg viewBox="0 0 24 24" width="18" height="18" stroke="currentColor" fill="none" strokeWidth="2">
+ <path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" />
+ <path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" />
+ </svg>
+ Private URL
+ </h3>
+ </div>
+
+ {!app.private_url_enabled ? (
+ <div className="private-url-disabled">
+ <p className="hint">
+ Enable a private, shareable URL for this application.
+ Private URLs are not publicly indexed and can be shared with specific people.
+ </p>
+ <form onSubmit={handleEnable} className="private-url-form">
+ <div className="input-group">
+ <span className="input-prefix">/p/</span>
+ <input
+ type="text"
+ value={customSlug}
+ onChange={handleSlugInput}
+ placeholder="custom-slug (optional)"
+ className="slug-input"
+ minLength={3}
+ maxLength={50}
+ />
+ </div>
+ <button
+ type="submit"
+ className="btn btn-primary"
+ disabled={loading}
+ >
+ {loading ? 'Enabling...' : 'Enable Private URL'}
+ </button>
+ </form>
+ <p className="slug-hint">
+ Leave empty to auto-generate a random slug, or enter your own custom slug.
+ </p>
+ </div>
+ ) : (
+ <div className="private-url-enabled">
+ <div className="private-url-display">
+ <div className="url-box">
+ <span className="url-label">Your private URL:</span>
+ <code className="url-value">{privateUrl}</code>
+ </div>
+ <div className="url-actions">
+ <button
+ className="btn btn-secondary btn-sm"
+ onClick={copyToClipboard}
+ title="Copy to clipboard"
+ >
+ <svg viewBox="0 0 24 24" width="14" height="14" stroke="currentColor" fill="none" strokeWidth="2">
+ <rect x="9" y="9" width="13" height="13" rx="2" ry="2" />
+ <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
+ </svg>
+ Copy
+ </button>
+ <button
+ className="btn btn-secondary btn-sm"
+ onClick={handleRegenerate}
+ disabled={loading}
+ title="Generate new random slug"
+ >
+ <svg viewBox="0 0 24 24" width="14" height="14" stroke="currentColor" fill="none" strokeWidth="2">
+ <polyline points="23 4 23 10 17 10" />
+ <polyline points="1 20 1 14 7 14" />
+ <path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15" />
+ </svg>
+ Regenerate
+ </button>
+ </div>
+ </div>
+
+ {editMode ? (
+ <form onSubmit={handleUpdateSlug} className="slug-edit-form">
+ <div className="input-group">
+ <span className="input-prefix">/p/</span>
+ <input
+ type="text"
+ value={customSlug}
+ onChange={handleSlugInput}
+ placeholder="new-slug"
+ className="slug-input"
+ minLength={3}
+ maxLength={50}
+ autoFocus
+ />
+ </div>
+ <button
+ type="submit"
+ className="btn btn-primary btn-sm"
+ disabled={loading || !customSlug}
+ >
+ Save
+ </button>
+ <button
+ type="button"
+ className="btn btn-secondary btn-sm"
+ onClick={() => {
+ setEditMode(false);
+ setCustomSlug('');
+ }}
+ >
+ Cancel
+ </button>
+ </form>
+ ) : (
+ <button
+ className="btn-link"
+ onClick={() => setEditMode(true)}
+ >
+ Change slug
+ </button>
+ )}
+
+ <div className="private-url-footer">
+ <button
+ className="btn btn-danger btn-sm"
+ onClick={handleDisable}
+ disabled={loading}
+ >
+ Disable Private URL
+ </button>
+ </div>
+ </div>
+ )}
+ </div>
+ );
+};
+
+export default PrivateURLSection;
diff --git a/frontend/src/services/api.js b/frontend/src/services/api.js
index 49bad4cf..10d7a0d2 100644
--- a/frontend/src/services/api.js
+++ b/frontend/src/services/api.js
@@ -1862,6 +1862,39 @@ class ApiService {
return this.request('/uptime/tracking/status');
}
+ // ========================================
+ // Private URL endpoints
+ // ========================================
+ async enablePrivateUrl(appId, slug = null) {
+ return this.request(`/apps/${appId}/private-url`, {
+ method: 'POST',
+ body: slug ? { slug } : {}
+ });
+ }
+
+ async getPrivateUrl(appId) {
+ return this.request(`/apps/${appId}/private-url`);
+ }
+
+ async updatePrivateUrl(appId, slug) {
+ return this.request(`/apps/${appId}/private-url`, {
+ method: 'PUT',
+ body: { slug }
+ });
+ }
+
+ async disablePrivateUrl(appId) {
+ return this.request(`/apps/${appId}/private-url`, {
+ method: 'DELETE'
+ });
+ }
+
+ async regeneratePrivateUrl(appId) {
+ return this.request(`/apps/${appId}/private-url/regenerate`, {
+ method: 'POST'
+ });
+ }
+
// ========================================
// Environment Variables endpoints
// ========================================
diff --git a/frontend/src/styles/components/_private-url.less b/frontend/src/styles/components/_private-url.less
new file mode 100644
index 00000000..f5f545a6
--- /dev/null
+++ b/frontend/src/styles/components/_private-url.less
@@ -0,0 +1,158 @@
+// ============================================
+// PRIVATE URL COMPONENT
+// ============================================
+
+.private-url-section {
+ background: @bg-card;
+ border: 1px solid @border-subtle;
+ border-radius: @radius-md;
+ padding: @space-5;
+ margin-bottom: @space-5;
+
+ .section-header {
+ margin-bottom: @space-4;
+
+ h3 {
+ display: flex;
+ align-items: center;
+ gap: @space-2;
+ margin: 0;
+ font-size: @font-size-lg;
+ font-weight: 500;
+ color: @text-primary;
+
+ svg {
+ color: @accent-primary;
+ }
+ }
+ }
+}
+
+.private-url-disabled {
+ .hint {
+ color: @text-secondary;
+ font-size: @font-size-sm;
+ margin-bottom: @space-4;
+ line-height: 1.5;
+ }
+
+ .slug-hint {
+ color: @text-tertiary;
+ font-size: @font-size-xs;
+ margin-top: @space-2;
+ }
+}
+
+.private-url-form,
+.slug-edit-form {
+ display: flex;
+ gap: @space-3;
+ align-items: center;
+ flex-wrap: wrap;
+
+ .input-group {
+ display: flex;
+ align-items: center;
+ flex: 1;
+ min-width: 200px;
+ }
+
+ .input-prefix {
+ background: @bg-tertiary;
+ border: 1px solid @border-subtle;
+ border-right: none;
+ border-radius: @radius-sm 0 0 @radius-sm;
+ padding: @space-2 @space-3;
+ color: @text-tertiary;
+ font-family: @font-mono;
+ font-size: @font-size-sm;
+ height: 40px;
+ display: flex;
+ align-items: center;
+ }
+
+ .slug-input {
+ flex: 1;
+ border-radius: 0 @radius-sm @radius-sm 0;
+ font-family: @font-mono;
+ min-width: 150px;
+ }
+}
+
+.private-url-enabled {
+ .private-url-display {
+ background: fade(@success, 10%);
+ border: 1px solid fade(@success, 30%);
+ border-radius: @radius-md;
+ padding: @space-4;
+ margin-bottom: @space-4;
+ }
+
+ .url-box {
+ display: flex;
+ flex-direction: column;
+ gap: @space-2;
+ margin-bottom: @space-3;
+ }
+
+ .url-label {
+ color: @text-secondary;
+ font-size: @font-size-sm;
+ }
+
+ .url-value {
+ background: @bg-secondary;
+ padding: @space-2 @space-3;
+ border-radius: @radius-sm;
+ font-family: @font-mono;
+ font-size: @font-size-sm;
+ color: @text-primary;
+ word-break: break-all;
+ user-select: all;
+ }
+
+ .url-actions {
+ display: flex;
+ gap: @space-2;
+ flex-wrap: wrap;
+ }
+}
+
+.btn-link {
+ background: none;
+ border: none;
+ color: @accent-primary;
+ cursor: pointer;
+ padding: 0;
+ font-size: @font-size-sm;
+
+ &:hover {
+ text-decoration: underline;
+ }
+}
+
+.slug-edit-form {
+ margin-top: @space-4;
+ padding-top: @space-4;
+ border-top: 1px solid @border-subtle;
+}
+
+.private-url-footer {
+ margin-top: @space-4;
+ padding-top: @space-4;
+ border-top: 1px solid @border-subtle;
+}
+
+// Private URL indicator in app list
+.private-url-indicator {
+ display: inline-flex;
+ align-items: center;
+ gap: @space-1;
+ color: @success;
+ font-size: @font-size-sm;
+
+ svg {
+ width: 14px;
+ height: 14px;
+ }
+}
diff --git a/frontend/src/styles/main.less b/frontend/src/styles/main.less
index bb87aaea..e3d4b928 100644
--- a/frontend/src/styles/main.less
+++ b/frontend/src/styles/main.less
@@ -41,6 +41,7 @@
@import 'components/_spinner';
@import 'components/_uptime';
@import 'components/_env-vars';
+@import 'components/_private-url';
@import 'components/_two-factor';
@import 'components/_notifications';
@import 'components/_query-runner';