From e57c4b24ad3615a28260d570c68777f089112c20 Mon Sep 17 00:00:00 2001
From: Shreerang Kale
Date: Mon, 21 Jul 2025 11:37:52 +0530
Subject: [PATCH] Remove salt
---
src/app/api/registry/route.ts | 34 +++++++++++---------------------
src/components/StatusDisplay.tsx | 8 ++++++--
src/components/URLForm.tsx | 22 ++++++++++-----------
3 files changed, 29 insertions(+), 35 deletions(-)
diff --git a/src/app/api/registry/route.ts b/src/app/api/registry/route.ts
index c42525f..0eae0eb 100644
--- a/src/app/api/registry/route.ts
+++ b/src/app/api/registry/route.ts
@@ -224,17 +224,9 @@ export async function POST(request: NextRequest) {
// Sanitize the app name to ensure it's DNS-compatible (only alphanumeric and dashes)
const sanitizedAppName = appName.replace(/[^a-zA-Z0-9-]/g, '-').toLowerCase();
- // Generate a random salt (6 alphanumeric characters) to prevent name collisions
- const generateSalt = (): string => {
- const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
- return Array.from({ length: 6 }, () => chars.charAt(Math.floor(Math.random() * chars.length))).join('');
- };
- const salt = generateSalt();
- console.log(`Generated salt: ${salt}`);
-
- // Create DNS name in format: app_name-shortcommithash-salt
- const dnsName = `${sanitizedAppName}-${shortHash}-${salt}`;
- console.log(`DNS name with salt: ${dnsName} (sanitized from: ${appName})`);
+ // Create DNS name in format: app_name-shortcommithash
+ const dnsName = `${sanitizedAppName}-${shortHash}`;
+ console.log(`DNS name: ${dnsName} (sanitized from: ${appName})`);
// Ensure the DNS name doesn't have consecutive dashes or start/end with a dash
let cleanDnsName = dnsName
@@ -243,10 +235,9 @@ export async function POST(request: NextRequest) {
// Ensure DNS name is valid (63 chars max per label, all lowercase, starts with a letter)
if (cleanDnsName.length > 63) {
- // If too long, truncate but preserve both the commit hash and salt parts
- const suffixPart = `-${shortHash}-${salt}`;
- const maxAppNameLength = 63 - suffixPart.length;
- cleanDnsName = sanitizedAppName.substring(0, maxAppNameLength) + suffixPart;
+ // If too long, truncate but preserve both the commit hash
+ const maxAppNameLength = 63 - shortHash.length;
+ cleanDnsName = sanitizedAppName.substring(0, maxAppNameLength) + shortHash;
}
// If the DNS name ended up empty (unlikely) or doesn't start with a letter (possible),
@@ -255,7 +246,7 @@ export async function POST(request: NextRequest) {
cleanDnsName = `app-${cleanDnsName}`;
}
- console.log(`Final DNS name with salt: ${cleanDnsName}`);
+ console.log(`Final DNS name: ${cleanDnsName}`);
// Set up Registry config
const config = getRegistryConfig()
@@ -273,9 +264,8 @@ export async function POST(request: NextRequest) {
const registry = getRegistry()
- // Create LRN for the application with commit hash and salt
- // We already have the salt from earlier, so we use it directly
- const lrn = `lrn://${config.authority}/applications/${appName}-${shortHash}-${salt}`;
+ // Create LRN for the application with commit hash
+ const lrn = `lrn://${config.authority}/applications/${appName}-${shortHash}`;
// Get current timestamp for the meta note
const timestamp = new Date().toUTCString();
@@ -284,7 +274,7 @@ export async function POST(request: NextRequest) {
console.log('Step 1: Publishing ApplicationRecord...');
const applicationRecord = {
type: 'ApplicationRecord',
- name: `${appName}-${shortHash}-${salt}`, // Include commit hash and salt in the record name
+ name: `${appName}-${shortHash}`, // Include commit hash in the record name
version: '1.0.0',
app_type: 'webapp',
repository: [repoUrl],
@@ -365,8 +355,8 @@ export async function POST(request: NextRequest) {
const deploymentRequestData = {
type: 'ApplicationDeploymentRequest',
version: '1.0.0',
- name: `${appName}-${shortHash}-${salt}`, // Update name to match application record
- application: lrn, // LRN already includes commit hash and salt
+ name: `${appName}-${shortHash}`, // Update name to match application record
+ application: lrn, // LRN already includes commit hash
deployer: deployerLrn,
dns: cleanDnsName,
config: {
diff --git a/src/components/StatusDisplay.tsx b/src/components/StatusDisplay.tsx
index 219b91d..aee8d5a 100644
--- a/src/components/StatusDisplay.tsx
+++ b/src/components/StatusDisplay.tsx
@@ -28,7 +28,7 @@ export default function StatusDisplay({
error,
}: StatusDisplayProps) {
// Get domain suffix from environment variable
- const domainSuffix = process.env.NEXT_PUBLIC_DOMAIN_SUFFIX || '';
+ const domainSuffix = process.env.NEXT_PUBLIC_DOMAIN_SUFFIX;
if (status === 'idle') return null;
const StatusBadge = ({ type }: { type: 'creating' | 'success' | 'error' }) => {
@@ -129,7 +129,11 @@ export default function StatusDisplay({
{appRecordId && }
{recordId && }
{lrn && }
- {dns && }
+ {dns && (
+ domainSuffix
+ ?
+ :
+ )}
)}
diff --git a/src/components/URLForm.tsx b/src/components/URLForm.tsx
index b5065a3..f62cac6 100644
--- a/src/components/URLForm.tsx
+++ b/src/components/URLForm.tsx
@@ -15,37 +15,37 @@ export default function URLForm({ onSubmit, disabled }: URLFormProps) {
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
-
+
// Trim the URL to remove any whitespace
const trimmedUrl = url.trim();
-
+
if (!trimmedUrl) {
setError('Please enter a URL');
return;
}
-
+
// Validate URL format
try {
const parsedUrl = new URL(trimmedUrl);
-
+
// Check for protocol
if (!parsedUrl.protocol.startsWith('http')) {
setError('URL must use HTTP or HTTPS protocol');
return;
}
-
+
// Check for hostname
if (!parsedUrl.hostname || parsedUrl.hostname.length < 3) {
setError('URL must contain a valid hostname');
return;
}
-
+
// Basic sanity check for common invalid URLs
if (parsedUrl.href === 'http://localhost' || parsedUrl.href === 'https://localhost') {
setError('Please enter a valid public URL, not localhost');
return;
}
-
+
// All validations passed
setError('');
onSubmit(trimmedUrl);
@@ -68,7 +68,7 @@ export default function URLForm({ onSubmit, disabled }: URLFormProps) {
onChange={(e) => setUrl(e.target.value)}
placeholder={exampleUrl}
className="w-full p-3 rounded-md transition-colors"
- style={{
+ style={{
background: 'var(--card-bg)',
border: '1px solid var(--input-border)',
color: 'var(--foreground)',
@@ -91,12 +91,12 @@ export default function URLForm({ onSubmit, disabled }: URLFormProps) {
)}
-
+