好吧,这是我的问题:我有一个我很满意的 HTML 页面,但我希望使其动态。我正在使用 Node 和 Express,我想知道是否有任何方法可以修改然后渲染纯 HTML。我不会使用 Jade 或任何其他模板引擎。
我的server.js:
var http = require('http');
var express = require('express');
var app = express()
var port = 3000;
var api_router = express.Router();
....
api_router.route('/webm/test/')
.get(function(req, res){
res.sendFile(__dirname + "/test.html")
})
app.use('/api/', api_router);
app.listen(port);
console.log("NodeJS Backend API running.");
目前这不起作用(未找到 HTML 模板引擎)。它也不能满足我的需求:我希望根据 GET 请求在标签中设置“src='blah.webm'”。
这是我要修改的页面:
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../stylesheet.css">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<div id="header">
<a href="../index.html"><p>../</p></a>
<p>TrentV.net : Trent VanSlyke</p>
</div>
<div class="container" style="display: flex">
<video id="player" src="CUSTOMIZE ME" controls></video>
<div id="related">
</div>
<script src="webm.js" type="text/javascript"></script>
</div>
</body>
</html>
最佳答案
您可以使用快速 View 模板,如here所述
关于javascript - 如何使用 Express 提供部分动态 HTML 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35633855/