[英]Calling server-side code from client on Derby.js
I'm new to using Derby.js, and have scaffolded out a project using the yeoman generator-derby package. 我是新手使用Derby.js,并使用yeoman generator-derby包构建了一个项目。 I thought everything was going fine, but I can't figure out what I'm doing wrong here.
我以为一切都很顺利,但我无法弄清楚我在这里做错了什么。
A breakdown: 细分:
In my app/index.js, I import this file and use it like so: 在我的app / index.js中,我导入此文件并像这样使用它:
app.proto.submitWp = function() { dbWp.createUser(this.model); };
I call this function from the view/index.jade like so: 我从view / index.jade中调用此函数,如下所示:
button.btn.btn-primary(type="button", on-click="submitWp()")
In the browser, I get numerous console.error message complaining about the 'fs' module not being defined. 在浏览器中,我收到许多console.error消息,抱怨未定义'fs'模块。 After much googling, I discover that it's due to Browserify ignoring the 'fs' module, which subsequently causes problems with modules 'mysql' and 'needle'.
经过大量的谷歌搜索,我发现这是由于Browserify忽略了'fs'模块,随后导致模块'mysql'和'needle'出现问题。 But that implies this code is being executed in the browser?
但这意味着此代码正在浏览器中执行?
So my question is: why is this trying to call the function on the client side? 所以我的问题是:为什么这会尝试在客户端调用该函数? Obviously if it executes on the server side, as I thought it was going to, there wouldn't be a problem requiring these modules.
显然,如果它在服务器端执行,正如我认为的那样,那就不需要这些模块了。
How can I execute this function on the server ? 如何在服务器上执行此功能? Had this working fine with express + socket.io before, but wanted to change frameworks and give Derby.js a shot.
如果这与之前的express + socket.io工作正常,但想改变框架并给Derby.js一个机会。
I'm clearly misunderstanding something about how Derby.js is supposed to work; 我显然误解了Derby.js应该如何工作; any help would be appreciated.
任何帮助,将不胜感激。 Thanks!
谢谢!
I know this is like 4 months later, but being new to DerbyJs too, I thought I could try and help. 我知道这就像4个月后,但对DerbyJs来说也是新手,我想我可以试着帮忙。
I personally with standard html code have the equivalent working. 我个人用标准的html代码有相同的工作。
<button on-click="editContact(#contact.id)">Edit Contact</button>
This indeed runs code on the server. 这确实在服务器上运行代码。 Can you try writing your code in standard HTML, or perhaps better yet, see if you can do a console.log on the server method to see if it even is getting there?
你可以尝试用标准HTML编写代码,或者更好的是,看看你是否可以在服务器方法上执行console.log来查看它是否到达那里?
Perhaps the best would be to call an empty function on the server with a console log and check both the browser console and the server console. 也许最好的方法是使用控制台日志调用服务器上的空函数,并检查浏览器控制台和服务器控制台。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.