Skip to content

Instantly share code, notes, and snippets.

@ibrow
Created September 30, 2011 20:25
Show Gist options
  • Save ibrow/1254879 to your computer and use it in GitHub Desktop.
Save ibrow/1254879 to your computer and use it in GitHub Desktop.
Experimenting with Middle End
/**
* Simple module for greeting people
**/
var Tidy = require('./tidy');
var Greetings = function() { }
Greetings.prototype.hello = function(who) {
who = Tidy.trim(who);
return this.hello(who);
}
module.exports = Greetings;
/**
* Client Side script, creating the "Middle End"
**/
var require = function(module) {
document.write('<script type="text/javascript" src="'+module+'.js"></script>');
}
var module = {
exports: undefined
};
<html>
<head><title>Testing the Middle End</title>
<script type="text/javascript" src="middleware.js"></script>
<script type="text/javascript">
require("greetings");
</script>
</head>
<body>
<script type="text/javascript">
var greetings = new Greetings();
document.write("<p>"+greetings.hello(' HTML ')+"!</p>");
</script>
</body>
</html>
/**
* NodeJS server side script for experimenting with the Middle End
**/
var Greetings = require('./greetings');
var greetings = new Greetings();
console.log(greetings.hello(' Node ')+"!");
/**
* Simple module to demonstrate sanitization
**/
var Tidy = {
whitespace: '\\r\\n\\t\\s',
trim: function(str) {
var whitespace = '\\r\\n\\t\\s';
str = str.replace(new RegExp('^['+this.whitespace+']+|['+this.whitespace+']+$', 'g'), '')
return str;
}
}
module.exports = Tidy;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment