Skip to content

Commit

Permalink
hasha import and shortner
Browse files Browse the repository at this point in the history
  • Loading branch information
rishz committed Mar 9, 2017
1 parent fe34a14 commit 1d8d1f8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"version": "1.0.0",
"main": "server.js",
"dependencies": {
"express": "^4.15.2"
"body-parser": "^1.17.1",
"express": "^4.15.2",
"hasha": "^2.2.0"
},
"devDependencies": {},
"scripts": {
Expand Down
10 changes: 9 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@


const express = require("express");

const bodyParser = require("body-parser");
const app = express();

const shortner = require("./shortner");

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}))
app.use(express.static("static"));
app.get('/:shortcode',(req,res) => {
let URL = shortner.expand(req.params.shortcode);
res.redirect(url);
});
app.listen(3000, function(){

console.log("Listening on port 3000")
Expand Down
18 changes: 18 additions & 0 deletions shortner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Created by rishabhshukla on 09/03/17.
*/

const hasha = require("hasha");

module.exports = {
shorten: function (url) {
if(url=='http://google.com'){
return 'xyz';
}
},
expand: function (shortcode) {
if(shortcode=='xyz'){
return 'http://google.com';
}
}
};

0 comments on commit 1d8d1f8

Please sign in to comment.