server/app.js
// we need this for serving js,css,html files
we need this for serving js,css,html files
we need this for serving js css html files
function handler(req, res) {
    logger.info('handler....', req.url)
    if(req.url.indexOf('.css') != -1){ 
        logger.info(req.url, 'serving CSS');
      fs.readFile(__dirname + '/public/base.css', function (err, data) {
        if (err) logger.info(err);
        res.writeHead(200, {'Content-Type': 'text/css'});
        res.write(data);
        res.end();
      });
    }else if(req.url.indexOf('.js') != -1){ 
        logger.info(req.url, 'serving CSS')
      fs.readFile(__dirname + '/public/client.js', function (err, data) {
        if (err) logger.info(err);
        res.writeHead(200, {'Content-Type': 'application/javascript'});
        res.write(data);
        res.end();
      });
    }else{
        fs.readFile(__dirname + '/public/index.html', function (err, data) {
            if (err) logger.info(err);
            res.writeHead(200, {'Content-Type': 'text/html'});
            res.write(data);
            res.end();
          });
    }
}
function handler ( req , res ) { logger . info ( 'handler....' , req . url ) if ( req . url . indexOf ( '.css' ) != - 1 ) { logger . info ( req . url , 'serving CSS' ) ; fs . readFile ( __dirname + '/public/base.css' , function ( err , data ) { if ( err ) logger . info ( err ) ; res . writeHead ( 200 , { 'Content-Type' : 'text/css' } ) ; res . write ( data ) ; res . end ( ) ; } ) ; } else if ( req . url . indexOf ( '.js' ) != - 1 ) { logger . info ( req . url , 'serving CSS' ) fs . readFile ( __dirname + '/public/client.js' , function ( err , data ) { if ( err ) logger . info ( err ) ; res . writeHead ( 200 , { 'Content-Type' : 'application/javascript' } ) ; res . write ( data ) ; res . end ( ) ; } ) ; } else { fs . readFile ( __dirname + '/public/index.html' , function ( err , data ) { if ( err ) logger . info ( err ) ; res . writeHead ( 200 , { 'Content-Type' : 'text/html' } ) ; res . write ( data ) ; res . end ( ) ; } ) ; } }
we need this for serving js,css,html files
we need this for serving js css html files
//req.url has the pathname, check if it conatins '.css' //req.url has the pathname, check if it conatins '.js'