私は Javascript と Nodejs の初心者であり、物事を整理する最善の方法がわかりません。Nodejs と V8 convert を使用して C++ API をラップすることにより、C++ アプリケーションの Web インターフェイスを作成しています。私が持っている質問は、Nodejs内の関数/グローバルへの参照を持つHTMLを提供するためにExpressを使用できる方法はありますか? それとも、それを行うために、HTML で res.write(html) タイプの呼び出しを多数持つことに頼る必要がありますか?
たとえば、C++ 構成 API からアクセスされるものをフォーム データに事前入力したいとします。C++ API は Nodejs モジュールにラップされています。現在、動的に生成する必要があるものはすべて(事前入力フォームなど)、次のようにします。
var novaconfig = require('./NodeAppConfig/build/Release/appconfig');
var AppConfiguration = new Appconfig.AppConfigBinding();
var express=require('express');
var app = express.createServer(express_options);
app.configure(function () {
app.use(express.methodOverride());
app.use(express.bodyParser());
app.use(app.router);
});
app.get('/configureApplication.html', function(req, res) {
console.log("[200] " + req.method + " to " + req.url);
res.writeHead(200, "OK", {'Content-Type': 'text/html'});
res.write('<HTML>');
res.write('<HEAD>');
res.write(' <link rel="stylesheet" type="text/css" href="configstyle.css" media="screen">');
res.write('</HEAD>');
res.write('<BODY>');
res.write('<label>');
res.write(Interface);
res.write('</label>');
res.write('<form method="post" action="/configureNovaSave">');
res.write('<input type="text" name="interface" value="');
res.write(AppConfiguration.GetCurrentInterface());
res.write('" /><br />');
res.write('<input type="submit" name="submitbutton" id="submitbutton" value="Save Settings" />');
res.write('</form>');
res.write("<br/>");
res.write('</BODY>');
res.write('</HTML>');
res.end();
});
しかし、これは明らかに悪い方法です。動的に生成された HTML をスタンドアロン ファイルに格納し、その中の AppConfiguration.GetCurrentInterface() にアクセスする方法はありますか? このようなファイルを整理するにはどうすればよいでしょうか?