2016-03-21 114 views
0

我在引用node.js服務器中的api模塊時讓我的node.js服務器運行出現問題。在node.js服務器(EdgeJS)中創建服務器並引用API

public static async void Start() 
{ 
    var data = 9; 

    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

返回功能(選項,CB){

'use strict'; 
var api = require('routes/api'); 
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 app = express(); 
app.use(bodyParser.urlencoded({'extended': 'true'})); // parse application/x-www-form-urlencoded 
app.use(bodyParser.json()); 
//app.get('/api/getDeviceCatalog', api.getDeviceCatalog); 
//app.get('/api/getDeviceDetails', api.getDeviceDetails); 
//app.get('/api/getDeviceImages', api.getDeviceImages);// parse application/json 

// 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('routes/api'); 

我收到一條錯誤

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

回答

0
var api = require('routes/api'); 

您的應用無法找到該文件。請問您的server.js路線相同