Ver código fonte

Add LINK_LENGTH variable (#254)

Mikhail Golovanov 6 anos atrás
pai
commit
7be595c3cc
3 arquivos alterados com 8 adições e 2 exclusões
  1. 3 0
      .example.env
  2. 4 1
      .template.env
  3. 1 1
      server/controllers/linkController.ts

+ 3 - 0
.example.env

@@ -4,6 +4,9 @@ PORT=3000
 # The domain that this website is on
 DEFAULT_DOMAIN="localhost:3000"
 
+# Generated link length
+LINK_LENGTH=6
+
 # Postgres database credential details
 DB_HOST=localhost
 DB_PORT=5432

+ 4 - 1
.template.env

@@ -4,6 +4,9 @@ PORT={{PORT}}
 # The domain that this website is on
 DEFAULT_DOMAIN={{DEFAULT_DOMAIN}}
 
+# Generated link length
+LINK_LENGTH={{LINK_LENGTH}}
+
 # Neo4j database credential details
 DB_URI={{DB_URI}}
 DB_USERNAME={{DB_USERNAME}}
@@ -57,4 +60,4 @@ MAIL_PASSWORD={{MAIL_PASSWORD}}
 REPORT_MAIL={{REPORT_MAIL}}
 
 # Support email to show on the app
-CONTACT_EMAIL={{CONTACT_EMAIL}}
+CONTACT_EMAIL={{CONTACT_EMAIL}}

+ 1 - 1
server/controllers/linkController.ts

@@ -36,7 +36,7 @@ const dnsLookup = promisify(dns.lookup);
 const generateId = async () => {
   const address = generate(
     "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
-    6
+    Number(process.env.LINK_LENGTH) || 6
   );
   const link = await findLink({ address });
   if (!link) return address;