本文介绍了如何使用Express服务部分动态HTML页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这是我的问题:我有一个非常满意的HTML页面,但是我希望使其动态化.我正在使用带有Express的Node,我想知道是否有任何方法可以修改然后呈现纯HTML.我不会使用Jade或任何其他模板引擎.

Alright, here's my issue: I have an HTML page I am quite happy with, but I wish to make it dynamic. I am using Node with Express, and I was wondering if there was any way to modify and then render plain HTML. I will not be using Jade or any other template engines.

我的server.js:

My 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'".

Currently this does not work (no templating engine for HTML found). It also does not fulfill my needs: I wish to set the "src='blah.webm'" in a tag depending on the GET req.

这是我要修改的页面:

<!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>

推荐答案

您可以使用如此处

这篇关于如何使用Express服务部分动态HTML页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 22:32