2016-10-20 10 views
0

は私が急行経由.ejs fileにサービスを提供しようとしていますが、私はここでエラーが

Error: No default engine was specified and no extension was provided. at new View (C:\development\dashboard\node_modules\express\lib\view.js:62:11) at EventEmitter.render (C:\development\dashboard\node_modules\express\lib\application.js:569:12) at ServerResponse.render (C:\development\dashboard\node_modules\express\lib\response.js:961:7) at C:\development\dashboard\app.js:51:7
at Layer.handle_error (C:\development\dashboard\node_modules\express\lib\router\layer.js:71:5) at trim_prefix (C:\development\dashboard\node_modules\express\lib\router\index.js:310:13) at C:\development\dashboard\node_modules\express\lib\router\index.js:280:7 at Function.process_params (C:\development\dashboard\node_modules\express\lib\router\index.js:330:12) at next (C:\development\dashboard\node_modules\express\lib\router\index.js:271:10) at Layer.handle_error (C:\development\dashboard\node_modules\express\lib\router\layer.js:67:12)

が私のファイル

index.ejsあり、このエラーを取得していますNode.jsの

<!DOCTYPE html> 
<html> 
<head> 
    <title>ETL Dashborad</title> 
    <script type="text/javascript" src="./resources/javascripts/jquery.min.js"></script> 
    <script> 
     window.GeorgeEnv = {}; 
     window.GeorgeEnv.serverRunOnEnv = "<%= runOnEnv %>"; 
    </script> 
</head> 
<body> 
    <div>HELLO</div> 
    <div id="app"></div> 
    <script type="text/javascript" src="./js/client.min.js"></script> 
</body> 
</html> 

index.js

var ejs = require('ejs'); 
var fs = require('fs'); 
var EnvConfig = require('../src/utils/EnvHandler.js'); 
module.exports = function(app, dirname) { 

    var content = fs.readFileSync(dirname + '/src/index.ejs', 'utf-8'); 
    var compiled = ejs.compile(content); 
    app.get("/", function(req, res){ 
     res.send(compiled({runOnEnv : EnvConfig.getProcessEnv()})); 
    }); 

    app.all('/healthcheck', require('./routes/healthcheck')); 
}; 

EnvHandler.js私はそれが正常に動作し、いくつかのテキストを返すために私index.jsファイルを変更

const qa2Config = require('../resources/env-configs/qa2/env-config'); 
const prodConfig = require('../resources/env-configs/prod/env-config'); 

// Fetching the Env from the index.ejb file 
var GeorgeEnv = GeorgeEnv || {}; 

var config = function() { 
    var envInfo = []; 
    envInfo['qa2'] = qa2Config.getEnvConfigs(); 
    envInfo['production'] = prodConfig.getEnvConfigs(); 
    var processEnv = process.env.NODE_ENV ? process.env.NODE_ENV : 'qa2'; 
    processEnv = process.env.NODE_ENV.trim(); 
    return { 
     getSsoUrl: function(env) { 
      if(env) { 
       return envInfo[env].ssoUrl; 
      } 
      return envInfo[processEnv].ssoUrl; 
     }, 
     getSelfUrl: function(env) { 
      if(env) { 
       return envInfo[env].selfUrl; 
      } 
      return envInfo[processEnv].selfUrl; 
     }, 
     getServerUrl: function(env) { 
      if(env) { 
       return envInfo[env].serverUrl; 
      } 
      return envInfo[processEnv].serverUrl; 
     }, 
     getRunOnPort: function(env) { 
      if(env) { 
       return envInfo[env].runOnPort; 
      } 
      return envInfo[processEnv].runOnPort; 
     }, 
     getProcessEnv: function() { 
      if(processEnv) { 
       return processEnv; 
      } 
      return 'qa2'; 
     } 
    } 
}(); 

res.send(compiled({runOnEnv : EnvConfig.getProcessEnv()}));の代わりにres.send('Hello');のような結果が得られます。 index.jsでconsole.log(content);を実行するとindex.ejsファイルが表示されることがあります

助けてください。

答えて

1

EnvHandler.jsが何もエクスポートしないためにエラーが発生します。あなたはそれが私のためにトリックをしたそうmodule.exports = config

EnvHandler.jsでEnvHandler.js

const qa2Config = require('../resources/env-configs/qa2/env-config'); 
const prodConfig = require('../resources/env-configs/prod/env-config'); 

// Fetching the Env from the index.ejb file 
var GeorgeEnv = GeorgeEnv || {}; 

var config = function() { 
    var envInfo = []; 
    envInfo['qa2'] = qa2Config.getEnvConfigs(); 
    envInfo['production'] = prodConfig.getEnvConfigs(); 
    var processEnv = process.env.NODE_ENV ? process.env.NODE_ENV : 'qa2'; 
    processEnv = process.env.NODE_ENV.trim(); 
    return { 
     getSsoUrl: function(env) { 
      if(env) { 
       return envInfo[env].ssoUrl; 
      } 
      return envInfo[processEnv].ssoUrl; 
     }, 
     getSelfUrl: function(env) { 
      if(env) { 
       return envInfo[env].selfUrl; 
      } 
      return envInfo[processEnv].selfUrl; 
     }, 
     getServerUrl: function(env) { 
      if(env) { 
       return envInfo[env].serverUrl; 
      } 
      return envInfo[processEnv].serverUrl; 
     }, 
     getRunOnPort: function(env) { 
      if(env) { 
       return envInfo[env].runOnPort; 
      } 
      return envInfo[processEnv].runOnPort; 
     }, 
     getProcessEnv: function() { 
      if(processEnv) { 
       return processEnv; 
      } 
      return 'qa2'; 
     } 
    } 
}(); 

module.exports = config; 
+0

のようなあなたの関数をエクスポートする必要があります。ありがとう – Jagrati