Example #1
0
  return (req, res) => {
    // set content type
    res.setHeader('content-type', 'text/html');

    // create html stream, gzip, then pipe to response
    const tr = trumpet();
    tr.pipe(oppressor(req)).pipe(res);

    // create a write stream to the .page selector
    const pageStream = tr.select('.page').createWriteStream();

    // check if the user is "logged in"
    const cookies = cookie.parse(req.headers.cookie || '');
    const isSession = cookies.session && has(sessions, cookies.session);

    if (isSession) {
      // pipe a read stream to the page selector
      const chat = trumpet();
      chat.pipe(pageStream);

      // update the usernmae
      const username = chat.select('.username').createWriteStream();
      username.end(sessions[cookies.session]);

      // pipe the chat html to the stream that pipes to .page
      fs.createReadStream('browser/pages/chat.html').pipe(chat);

    } else {
      // pipe the rendered html to stream that pipes to .page
      fs.createReadStream(`browser/pages/${page}.html`).pipe(pageStream);
    }

    // pipe the root html to the html stream
    fs.createReadStream('browser/index.html').pipe(tr);
  };
Example #2
0
var server = http.createServer(function (req, res) {
    var stream = fs.createReadStream(__dirname + '/data.txt');
    stream.on('error', function(err) {
        res.statusCode = 500;
        res.send(String(err));
    });

    stream.pipe(oppressor(req)).pipe(res);
});
Example #3
0
    app.route('/client.js',function(req,res){
      var out = bundle('app.js','client/app.js');
      res.setHeader('Content-Type','text/javascript'); 
      res.setHeader('Expires',(new Date(0)).toString());

      var oppress = oppressor(req);
      oppress.pipe(res);
      oppress.end(out);
    });
Example #4
0
  response.render = function(view, data) {

    var handlebars = new Handlify(data || {});

    try { fs.lstatSync(state.viewLocation) }
    catch (err) { console.log(err) };

    /* Use app state to get view location */
    var location = path.resolve(state.viewLocation + '/' + view + '.html');
    /* Open a read stream and pipe it through any transforms */
    var stream = fs.createReadStream(location);
    stream.pipe(handlebars).pipe(oppressor(request)).pipe(this);
  }
Example #5
0
function js(req, res){
  var browserify = require('browserify')
    , oppressor = require('oppressor')
    , path = require('path')
    , bundle

  res.setHeader('content-type', 'application/javascript')

  bundle = browserify()
  .add(path.resolve(__dirname, '../../browser/index.js'))
  .bundle()
  .pipe(oppressor(req))
  .pipe(res)

}
Example #6
0
SinglePageClient.prototype.view = function(request){

  var preprocessor = this.app.preprocessors[this.viewExtension];
  
  // Start with raw HTML
  var view = this.html(request)

  // Pre-process Jade or whatever into proper HTML
  if (preprocessor) view = view.pipe(preprocessor)

  // Inject Asset Tags into HTML
  view = view.pipe(this.injectAssetTags())

  // GZip output if browser supports it
  view.pipe(oppressor(request))

  return view;
}
Example #7
0
			fs.exists( filepath, function( exists ) {

				if( !exists ){
					console.log( filepath + ' does not exist' );

					/* Handle 404 if requested page does not exist */
					response.writeHead(404, {'Content-Type': 'text/plain'});

					if(!config.error_page){
						pageError( response );
					}
					else{
						var err_page_path = config.path + config.error_page;
						console.log( 'error page path'.cyan + err_page_path );
						fs.exists( err_page_path, function( exists ){

							if( exists ){
								console.log( 'found error page' );

								var fileStream = fs.createReadStream( err_page_path );
								fileStream.pipe( response );
							}
							else{
								/* 404 inception occurs when the custom 404 page cannot be found */
								pageError( response );
							}
						} );
					}
				}else{

					/* Get the mime type */
					var type = mime.lookup( filepath );

					var fileStream = fs.createReadStream( filepath );

					if( config.compress ){
						fileStream.pipe( oppressor( request ) ).pipe( response );
					}
					else{
						response.writeHead( 200, { 'Content-Type' : type } );
						fileStream.pipe( response );
					}
				}
			} );
Example #8
0
      return exports.get_css(ua, locale, fonts, function(err, cssObj) {
        // ignore any other errors and let a higher level deal with the
        // situation.
        if (err instanceof InvalidFontError) {
          next();
        }
        else if (err) {
          throw err;
        }
        else {
          res.on('header', function() {
            setCacheControlHeaders(res);
          });

          if (compress) {
            req.pipe(filed(cssObj.cssPath)).pipe(oppressor(req)).pipe(res);
          }
          else {
            req.pipe(filed(cssObj.cssPath)).pipe(res);
          }
        }
      });
Example #9
0
function Root () {
    filed('views/index.html')
        .pipe(oppressor(this.req))
        .pipe(this.res);
}
var server = http.createServer(function (req, res) {
    filed(__dirname + '/data.txt')
        .pipe(oppressor(req))
        .pipe(res)
    ;
});
let server = http.createServer(function (req, res) {
    fs.createReadStream(__filename)
    	.pipe(oppressor(req))
    	.pipe(res)
})
Example #12
0
 app.route('/media.js',function(req,res){
   var out = bundle('media.js','media.js'); 
   var oppress = oppressor(req);
   oppress.pipe(res);
   oppress.end(out);
 });
var server = http.createServer(function (req, res) {
    var stream = fs.createReadStream(__dirname + '/data.txt');
    stream.pipe(oppressor(req)).pipe(res);
});
Example #14
0
 "serve": function(req, res, data) {
     var s = oppressor(req);
     s.end(data);
     s.pipe(res);
 }
server = http.createServer(function (req, res) {
    fs.createReadStream(__dirname + "/data.txt")
        .pipe(oppressor(req))
        .pipe(res);
});
Example #16
0
routes.root = function () {
    // Ensure there is a user agent
    filed(__dirname + '/views/index.html')
        .pipe(oppressor(this.req))
        .pipe(this.res);
};
Example #17
0
 setTimeout(function(){
     stream.pipe(oppressor(req))
     cb(stream);
 }, 0);