Created
November 15, 2016 21:59
-
-
Save rob0t7/cbf3ce847bc2c12c8ce421384c9bdb21 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/express_server.js b/express_server.js | |
index f65b4dd..d2e24c3 100644 | |
--- a/express_server.js | |
+++ b/express_server.js | |
@@ -1,4 +1,4 @@ | |
-//"use strict"; | |
+"use strict"; | |
const bcrypt = require('bcrypt'); | |
const cookieSession = require('cookie-session'); | |
const express = require("express"); | |
@@ -53,7 +53,7 @@ const generateRandomString = function(lengthOfString){ | |
let randomString = ""; | |
const characters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
for (var i = 0; i < lengthOfString; i++){ | |
- random = Math.floor(Math.random() * characters.length); | |
+ let random = Math.floor(Math.random() * characters.length); | |
randomString += characters[random]; | |
} | |
return randomString; | |
@@ -63,7 +63,7 @@ const generateId = function(lengthOfId){ | |
let randomString = ""; | |
const characters = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
for (var i = 0; i < lengthOfId; i++){ | |
- random = Math.floor(Math.random() * characters.length); | |
+ let random = Math.floor(Math.random() * characters.length); | |
randomString += characters[random]; | |
} | |
return randomString; | |
@@ -161,7 +161,7 @@ app.get("/urls/new", (req, res) => { //Renders page where users create new links | |
app.post("/urls", (req, res) => { //Applies logic when new URL is created and indexed with long URL | |
if(req.session.email){ | |
if (req.body.longURL.indexOf("http:/") !== -1 || req.body.longURL.indexOf("https:/") !== -1){ | |
- newShort = generateRandomString(6); | |
+ let newShort = generateRandomString(6); | |
urlDatabase[req.session.email][newShort] = req.body.longURL; | |
res.redirect("/urls"); | |
} | |
@@ -242,9 +242,3 @@ app.listen(PORT, () => { | |
console.log(`Tiny_app server listening on port ${PORT}!`); | |
}); | |
- | |
- | |
- | |
- | |
- | |
- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/package.json b/package.json | |
index 7407370..86bdb4b 100644 | |
--- a/package.json | |
+++ b/package.json | |
@@ -3,7 +3,7 @@ | |
"version": "1.0.0", | |
"main": "index.js", | |
"scripts": { | |
- "test": "echo \"Error: no test specified\" && exit 1" | |
+ "start": "node express_server.js" | |
}, | |
"author": "", | |
"license": "ISC", |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment