Using node.js in production: tempalias.com

Philip Hofstetter

gnegg.ch

About me

tempalias.com

Demo time

requirements

making it look nice

easy if you have a friend who understands design.

huge thanks to Richard Haydon

how email works

Basically just like your everyday letter

* let's ignore the Received header or 8bitmime this time around.

how tempalias works

keeping it accessible

Despite the complexity, everybody should be able to toy with this

There's only one option: Build an SMTP proxy (and the web service of course)

smtp proxy

persistence

alias generation

alias removal

give me code!

You are right - this is looking like a sales pitch - we are coders. Dammit.

dependencies

tempalias uses some external libraries (using git submodules)

It's a good idea to clone your dependencies and use your clone as the submodule source. You will make modifications to your clones!

web service

web framework

Began development using express. Since thrown away, replaced by own code and paperboy

web service

While it's really cool, sometimes generated HTML can still be useful

awesome node

bookmarklet

bookmarklet

Check if we were already loaded, otherwise, inject a script tag.

Note how I have to pass the hostname as part of the bookmarklet as the injected script is static JS and doesn't know the hostname (and I don't want to hardcode it)

(function(){
  var c = {h: 'localhost:8080', d:1, t:'pilif@gnegg.ch', u:2};
  if (window.$__tempalias_com){
    window.$__tempalias_com(c);
  }else{
    var s=document.createElement('script');
    s.src='http://localhost:8080/bookmarklet.js';
    s.onload = function(){
      window.$__tempalias_com(c);
    };
    document.getElementsByTagName('head')[0].appendChild(s);
  }
})();

bookmarklet

Use jQuery if the one we want is already there. Otherwise, carefully load our own

(function(){
   var ta_jquery = undefined;

   var bm = function(adata){
     var tempalias = function($){ /* lots of code */ }
      if (ta_jquery){
       tempalias(ta_jquery);
     }
     if (window.jQuery && (window.jQuery().jquery == '1.4.2')){
       ta_jquery = window.jQuery;
       tempalias(ta_jquery);
     }else{
       (function(){
         var old_jQuery = window.jQuery;
         var conflictProtect = (typeof window.$=='function');
         var s = document.createElement('script');
         s.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');
         s.onload = function(){
           ta_jquery = window.jQuery;
           if (conflictProtect)
             ta_jquery.noConflict();
           window.jQuery = old_jQuery;
           tempalias(ta_jquery);
         };
         document.getElementsByTagName('head')[0].appendChild(s);
       }());
     }
   };
   window.$__tempalias_com = bm;
 }());

@brainlock who sits in the audience could tell you a story of what can happen if you inject into the global namespace

and then, this happened

SPAM prevention

production use

we still went down


$ lsof -p 14749 | grep WAIT | wc -l
169
after a week - so it's much better.

Outlook

and now hurry and follow @pilif