我有以下最小的基本快速节点js应用程序:
var express = require ('express');
var app = express ();
app.get ('/', function (req, res) {
res.send ('Hello');
});
app.listen (3000);
Run Code Online (Sandbox Code Playgroud)
当我在localhost:3000上访问此站点时,我收到的响应如下:

如果我res.send ('Hello');改为res.end ('Hello');,响应是一个不同的字体,如:

我好奇; 为什么差异?
我想知道如何使用 Express 提供 svg 文件。
这是我到目前为止所做的尝试:
svg 文件
<svg width="400" height="180">
<g>
<rect x="50" y="20" rx="20" ry="20" width="150" height="150"
style="fill:red;stroke: black;stroke-width:5;opacity:0.5"></rect>
</g>
</svg>
Run Code Online (Sandbox Code Playgroud)
路线文件
var express = require('express');
var router = express.Router();
router.get('/myRoute', function (req, res, next) {
res.setHeader('Content-Type', 'image/svg+xml');
res.sendFile('../views/status.svg');
});
module.exports = router;
Run Code Online (Sandbox Code Playgroud)
但是当我将浏览器指向该路线时,出现以下错误:
This page contains the following errors:
error on line 1 at column 103: Opening and ending tag mismatch: link line 0 and head
Below is a rendering of the page up to the first …Run Code Online (Sandbox Code Playgroud)