使用edge.js在c#中启动nodejs服务器时引用节点模块时出错

时间:2016-04-22 22:01:18

标签: javascript c# node.js

我正在尝试让我的nodejs服务器在使用Edgejs启动我的Windows窗体应用程序时运行。我在引用我的api模块时遇到了打嗝。这是EdgeJS中的一个我无法控制并需要找到解决方法的错误吗?如果我改为使用API​​控制器怎么办?注意:在我的Web应用程序中使用相同的确切代码时,它会按预期运行。

c#启动文件

public static async void Start()
{

    var createHttpServer = Edge.Func(File.ReadAllText("../../../../server/server.js"));


    await createHttpServer(new
    {
        port = 3333,
    });


}

static void Main(string[] args)
{
    Task.Run((Action)Start).Wait();
    Application.Run(new Form1());
}

server.js

"use strict";

var http = require('http');
var express    = require('express');                    // web framework
var cors       = require('cors');                       // middleware for express
var bodyParser = require('body-parser');                // parsing module
var path       = require('path');
var edge       = require('edge');
var api = require('./api.js');


return function (options, cb) {
var app = express();
app.use(bodyParser.urlencoded({'extended': 'true'}));   // parse application/x-www-form-urlencoded
app.use(bodyParser.json());

app.get('/api/getFullCatalog', api.getFullCatalog());

// IMPORTANT!: This rule has to be last rule for routing as it has very common definition
app.all('/*', function (request, response) {
    var fileName, serverPath;
    console.log('Send: ' + __dirname + request.url);
    serverPath = path.resolve(__dirname + '../../../../../../server/');
    fileName = serverPath + request.url;

    response.sendFile(fileName);
});

// start server listening on defined port
app.listen(options.port);
console.log('The NodeJS server is ready.');
};

我可以启动服务器并在删除所述模块时运行

var api = require('./api');

这是错误

{"Error: Cannot find module './api.js'\n    
at Function.Module._resolveFilename (module.js:336:15)\n    
at Function.Module._load (module.js:286:25)\n    
at Module.require (module.js:365:17)\n    
at require (module.js:384:17)\n    
at eval (eval at <anonymous> (C:\\TechSpikeUDC\\TechSpikeUDC\\WpfApplication1\\bin\\x86\\Debug\\edge\\double_edge.js:34:28), <anonymous>:9:11)\n    
at compileFunc (C:\\TechSpikeUDC\\TechSpikeUDC\\WpfApplication1\\bin\\x86\\Debug\\edge\\double_edge.js:35:16)"}
(C:\\TechSpikeUDC\\TechSpikeUDC\\TechSpikeUDC\\bin\\x86\\Debug\\edge\\double_edge.js:34:28), <anonymous>:37:15)"}   System.Exception

同样,只有在胖客户端c#应用程序中使用时才会发生这种情况。

感谢任何帮助......谢谢。

0 个答案:

没有答案