渲染svg文件并使用express服务 [英] render svg file and serve it using express
本文介绍了渲染svg文件并使用express服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何使用Express渲染和提供svg文件.
I would like to know how to render and serve an svg file using Express.
现在,我可以将svg用作原始XML文件.这是我在做什么:
Right now, I can serve an svg as a raw XML file. Here is what I am doing:
路线
router.get('/status', function (req, res, next) {
res.setHeader('Content-Type', 'image/svg+xml');
res.sendFile(path.join(__dirname, '../views/status.svg'));
});
svg
<svg width="400" height="180">
<rect x="50" y="20" rx="20" ry="20" width="150" height="150" style="fill:red;stroke: black;stroke-width:5;opacity:0.5" />
</svg>
当我点击该路线时,svg文件的原始XML将被提供给浏览器.如何先将其渲染为SVG图像,然后再投放?
When I hit that route, the raw XML of the svg file is served to the browser. How can I render it first as an SVG image, and then serve it?
推荐答案
将SVG文件修改为此
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="400" height="180">
<rect x="50" y="20" rx="20" ry="20" width="150" height="150" style="fill:red;stroke: black;stroke-width:5;opacity:0.5" />
</svg>
这篇关于渲染svg文件并使用express服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文