使用带有socketstream的node.js时,不会加载客户端js文件

时间:2012-12-31 10:14:31

标签: node.js socketstream

我正在使用node.js和socketstream.Client方js文件没有加载,并且在调用服务器方法时,我在客户端没有定义ss错误。

  This is my  app.js file

   var ss = require('socketstream'), 
  express = require('express');
  var app = express(); 
 // Code & Template Formatters 
 ss.client.formatters.add(require('ss-stylus')); 
 ss.client.templateEngine.use(require('ss-hogan')); 
   ss.client.define('main',
    { view: 'app.html', 
    css: ['libs/reset.css', 'app.styl'], 
   code: ['libs/jquery.min.js', 'app'], 
     tmpl: '*' }); 
 // Use Express to route requests 
  app.get('/', function(req, res){ 
  res.serveClient('main'); });
  server = app.listen(3000); 
  ss.start(server);
  // Append SocketStream middleware to the stack 
  app.stack = ss.http.middleware.stack.concat(app.stack);


   This is my server side method rpc method
     exports.actions = function(req, res, ss){

    return {

        saveUserInfo: function(name,pwd){
        console.log(name);
        console.log(pwd);
        res('name is '+name + '&'+'password is '+pwd);

      }

        }
       }

1 个答案:

答案 0 :(得分:0)

ss.rpc函数采用rpc文件的名称,后跟函数名称。例如,如果文件名为 server / rpc / authentication.js ,那么您可以从客户端调用此文件:

ss.rpc('authentication.saveUserInfo', name, pwd, function(response){
  console.log(response);
});