Sun*_*Cho 6 svg node.js express
我想知道如何使用 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 error.
Run Code Online (Sandbox Code Playgroud)
我不知道为什么这不起作用,也不知道“第 103 列第 1 行”指向哪里。我的代码库中没有这样的行和列。
有什么建议么?
尝试发送 svg 来查看但没有问题
res.sendFile('../views/status.svg');
Run Code Online (Sandbox Code Playgroud)
对 sendFile 使用绝对链接
res.sendFile(__dirname + '/views/status.svg');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11796 次 |
| 最近记录: |