-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 90a83c4
Showing
10 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Nodejs + Express + Redis apps |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
express = require("express") | ||
redis = require("redis") | ||
|
||
redis_client = redis.createClient() | ||
|
||
app = module.exports = express.createServer() | ||
app.configure -> | ||
app.set "views", __dirname + "/views" | ||
app.set "view engine", "jade" | ||
app.use express.bodyParser() | ||
app.use express.methodOverride() | ||
app.use app.router | ||
app.use express.static(__dirname + "/public") | ||
|
||
app.configure "development", -> | ||
app.use express.errorHandler( | ||
dumpExceptions: true | ||
showStack: true | ||
) | ||
|
||
app.configure "production", -> | ||
app.use express.errorHandler() | ||
|
||
app.get "/songs", (req,res) -> | ||
render_now = false | ||
redis_client.get "global:nextSongId", (err,reply) -> | ||
songs=[] | ||
for uid in [1..reply] | ||
console.log uid | ||
redis_client.get "uid:"+uid+":songname",(err1,reply1) -> | ||
console.log reply1 | ||
songs[uid] = reply1 | ||
console.log songs.length | ||
if songs.length is reply | ||
console.log "Songs: " + songs | ||
res.render "songs", title: "Listing of all the songs",song_name: songs | ||
|
||
app.get "/", (req, res) -> | ||
res.render "index", title: "Excellent Song Suggest" | ||
|
||
app.post "/", (req, res) -> | ||
redis_client.incr "global:nextSongId", (err,reply) -> | ||
console.log "song id: " + reply | ||
redis_client.set "songname:"+req.body.song.name+":id",reply,redis.print | ||
redis_client.set "uid:"+reply+":songname",req.body.song.name,redis.print | ||
|
||
title= "Song posted sucessfully" | ||
res.render "new", song_name: req.body.song.name,title: title | ||
|
||
app.listen 3000 | ||
console.log "Express server listening on port %d", app.address().port |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
(function() { | ||
var app, express, redis, redis_client; | ||
express = require("express"); | ||
redis = require("redis"); | ||
redis_client = redis.createClient(); | ||
app = module.exports = express.createServer(); | ||
app.configure(function() { | ||
app.set("views", __dirname + "/views"); | ||
app.set("view engine", "jade"); | ||
app.use(express.bodyParser()); | ||
app.use(express.methodOverride()); | ||
app.use(app.router); | ||
return app.use(express.static(__dirname + "/public")); | ||
}); | ||
app.configure("development", function() { | ||
return app.use(express.errorHandler({ | ||
dumpExceptions: true, | ||
showStack: true | ||
})); | ||
}); | ||
app.configure("production", function() { | ||
return app.use(express.errorHandler()); | ||
}); | ||
app.get("/songs", function(req, res) { | ||
var render_now; | ||
render_now = false; | ||
return redis_client.get("global:nextSongId", function(err, reply) { | ||
var songs, uid, _results; | ||
songs = []; | ||
_results = []; | ||
for (uid = 1; 1 <= reply ? uid <= reply : uid >= reply; 1 <= reply ? uid++ : uid--) { | ||
console.log(uid); | ||
_results.push(redis_client.get("uid:" + uid + ":songname", function(err1, reply1) { | ||
console.log(reply1); | ||
songs[uid] = reply1; | ||
console.log(songs.length); | ||
if (songs.length === reply) { | ||
console.log("Songs: " + songs); | ||
return res.render("songs", { | ||
title: "Listing of all the songs", | ||
song_name: songs | ||
}); | ||
} | ||
})); | ||
} | ||
return _results; | ||
}); | ||
}); | ||
app.get("/", function(req, res) { | ||
return res.render("index", { | ||
title: "Excellent Song Suggest" | ||
}); | ||
}); | ||
app.post("/", function(req, res) { | ||
var title; | ||
redis_client.incr("global:nextSongId", function(err, reply) { | ||
console.log("song id: " + reply); | ||
redis_client.set("songname:" + req.body.song.name + ":id", reply, redis.print); | ||
return redis_client.set("uid:" + reply + ":songname", req.body.song.name, redis.print); | ||
}); | ||
title = "Song posted sucessfully"; | ||
return res.render("new", { | ||
song_name: req.body.song.name, | ||
title: title | ||
}); | ||
}); | ||
app.listen(3000); | ||
console.log("Express server listening on port %d", app.address().port); | ||
}).call(this); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "application-name" | ||
, "version": "0.0.1" | ||
, "private": true | ||
, "dependencies": { | ||
"jade": ">= 0.0.1" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
body { | ||
padding: 50px; | ||
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; | ||
} | ||
|
||
a { | ||
color: #00B7FF; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
// Run $ expresso | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var app = require('../app') | ||
, assert = require('assert'); | ||
|
||
|
||
module.exports = { | ||
'GET /': function(){ | ||
assert.response(app, | ||
{ url: '/' }, | ||
{ status: 200, headers: { 'Content-Type': 'text/html; charset=utf-8' }}, | ||
function(res){ | ||
assert.includes(res.body, '<title>Express</title>'); | ||
}); | ||
} | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
h1= title | ||
form#new_song(method='post') | ||
label Song Name: | ||
input(name='song[name]', type='text') | ||
input(name='Save',value='Save',type='submit') |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
!!! | ||
html | ||
head | ||
title= title | ||
link(rel='stylesheet', href='/stylesheets/style.css') | ||
body!= body |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
h1= "Please suggest song similar to " | ||
h2= song_name |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
h1= "Songs stored in the Redis Database" | ||
p= song_name |