Skip to content

Instantly share code, notes, and snippets.

@loganwm
Created August 6, 2013 08:58
Show Gist options
  • Save loganwm/6162885 to your computer and use it in GitHub Desktop.
Save loganwm/6162885 to your computer and use it in GitHub Desktop.
Dirt simple NodeJS/Express sample
var express = require("express");
var app = express();
app.configure(function()
{
app.use(express.compress());
app.use(express.bodyParser());
app.use("/", express.static(__dirname + "/public/", {maxAge: 86400000}));
});
app.listen(80);
app.get("/", function(request, response)
{
var stream = fs.createReadStream("./index.html");
stream.pipe(response);
});
app.get("/view/directory", function(request, response)
{
response.write(JSON.stringify(summit_directory));
response.end();
});
app.get("/search/:query", function(request, response)
{
var results = SearchByAny(unescape(request.params.query),15);
response.write(JSON.stringify(results));
response.end();
});
app.get("/search/byname/:query", function(request, response)
{
var results = SearchByName(unescape(request.params.query),15);
response.write(JSON.stringify(results));
response.end();
});
app.get("/search/bydescription/:query", function(request, response)
{
var results = SearchByDescription(unescape(request.params.query),15);
response.write(JSON.stringify(results));
response.end();
});
app.get("/view/list/:list", function(request, response)
{
if (!(request.params.list in lists))
{
response.write("{}");
response.end();
return;
}
var results = lists[request.params.list];
response.write(JSON.stringify(results));
response.end();
});
app.get("/lists", function(request, response)
{
response.write(JSON.stringify(Object.keys(lists)));
response.end();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment