Permalink
Browse files

stub out a very simple server for myfavoritebeer.org

  • Loading branch information...
1 parent 88f904a commit e28325c4b089e8f045ee4fc888f0d36ec00e2af9 @lloyd committed Sep 2, 2011
Showing with 61 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +9 −0 package.json
  3. +50 −0 server/main.js
View
@@ -0,0 +1,2 @@
+node_modules
+*~
View
@@ -0,0 +1,9 @@
+{
+ "name": "myfavoritebeer",
+ "version": "0.0.1",
+ "dependencies": {
+ "express": "2.4.6",
+ "postprocess": "0.0.1",
+ "connect-cookie-session" : "0.0.1"
+ }
+}
View
@@ -0,0 +1,50 @@
+#!/usr/bin/env node
+
+// require libraries that we depend on
+const
+express = require('express'),
+sessions = require('connect-cookie-session'),
+path = require('path'),
+postprocess = require('postprocess');
+
+// the key with which session cookies are encrypted
+const COOKIE_SECRET = process.env.SEKRET || 'you love, i love, we all love beer!';
+
+var app = express.createServer();
+
+// for local development we'll install a substitution middleware
+if (process.env.BROSWERID_URL) {
+ console.log("Using BrowserID at: " + process.env.BROSWERID_URL);
+ app.use(postprocess.middleware(function(body) {
+ return body.toString().replace(new RegExp("https://browserid.org", 'g'), process.env.BROSWERID_URL);
+ }));
+}
+
+// and now for the wsapi api
+
+app.post("/api/login", function (req, res) {
+ console.log("login called");
+ res.json(false);
+});
+
+app.post("/api/logout", function (req, res) {
+ console.log("logout called");
+ res.json(false);
+});
+
+app.get("/api/get", function (req, res) {
+ console.log("you want to get your favorite beer, eh?");
+ res.json(false);
+});
+
+app.get("/api/set", function (req, res) {
+ console.log("you want to set your favorite beer, eh?");
+ res.json(false);
+});
+
+// serve static resources
+app.use(express.static(path.join(path.dirname(__dirname), "static")));
+
+app.listen(process.env.PORT || 0, '127.0.0.1', function () {
+ console.log("listening on http://l27.0.0.1:" + app.address().port);
+});

0 comments on commit e28325c

Please sign in to comment.