Meteor JS在客户端html上模拟服务器命令行

 你虚伪的敷衍 发布于 2023-01-12 12:35

我是Meteor的新手,想要制作一个简单的应用程序.我无法根据http://terokaisti.blogspot.com/2012/10/writing-terminal-app-with-meteor-js.html模拟服务器端的命令行

在客户端(Mac OSX Mavericks),结果只是空白我输入命令并点击"运行"按钮.我正在使用上面网站的确切代码,除了我有autorun和exec = Npm.require('child_process').exec;

下面是我的html和js文件......

TerminalApp.html


  MeteorJS terminal



  {{> terminal}}



TerminalApp.js

// A collection for stdouts
var Replies = new Meteor.Collection('replies');

if(Meteor.is_client) {

 // Start listening changes in Replies
    Meteor.autorun(function() {
        Meteor.subscribe('replies');
    });

 // Set an observer to be triggered when Replies.insert() is invoked
 Replies.find().observe({
  'added': function(item) {
   // Set the terminal reply to Session
   Session.set('stdout', item.message);
  }
 });

 // Show the last command in input field
 Template.terminal.last_cmd = function() {
 return Session.get('last_cmd');
 };

 // Show the last shell reply in browser
 Template.terminal.window = function() {
  return Session.get('stdout');
 };

 // Add an event listener for Run-button
 Template.terminal.events = {
  'click [type="button"]': function() {
   var cmd = $('#command').val();
   Session.set('last_cmd', cmd);

   // Call the command method in server side
   Meteor.call('command', cmd);
  }
 }; 
}

if(Meteor.is_server) {
 var exec;

 // Initialize the exec function
 Meteor.startup(function() {
  exec = Npm.require('child_process').exec;
 });

 // Trigger the observer in Replies collection
    Meteor.publish('replies', function() {
        return Replies.find();
    });

 Meteor.methods({
  'command': function(line) {
   // Run the requested command in shell
   exec(line, function(error, stdout, stderr) {
    // Collection commands must be executed within a Fiber
    Fiber(function() {
     Replies.remove({});
     Replies.insert({message: stdout ? stdout : stderr});
    }).run();
   });
  }
 });
}

我错过了什么?我怎么调试?提前致谢!

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有