node.jsを使ってサーバーを作る練習をしています。メトロ UI/メトロ 4 フレームワークを含む HTML を作成しました。HTMLを開くことは問題ありませんでした。
しかし、それをノードサーバーに統合しようとすると. レンダリングはしましたが、metro UI フレームワークを読み取りませんでした。プレーンテキストやその他のものをレンダリングしました。良いUIはまったくありません。
しかし、エクスプレスを試してみると、パッケージ全体が問題なくレンダリングされました。
非明示的な読み取り HTML を使用して HTML をレンダリングする方法はありますか? または、metro UI /metro 4 フレームワークで HTML をレンダリングするには、この express.js が必要ですか?
あなたが私を助けることができるように、私は以下の私のコードをリストしました. ありがとう!
const fs = require('fs');
const http = require('http');
const url = require('url');
///// non express reading html
const mainHtml = fs.readFileSync(`${__dirname}/Main.html`, 'utf-8');
const server = http.createServer((req,res) => {
const pathName = req.url;
fs.readFile('./${__dirname}/main.html`, .html', function (err,html){
if (err) throw err;
res.writeHead(200,{ 'content-type': 'text/html' });
res.write(html);
res.end();
});
});
//using express
const express = require("express");
const app = express();
app.listen(7000, () => {
console.log("Application started and Listening on port 3000");
});
// server your css as static
app.use(express.static(__dirname));
app.get("/", (req, res) => {
res.sendFile(__dirname + "/Main.html");
});