Nodejs [DUING] 进度条图标 SVG 生成器服务
Nodejs [DUING] 进度条图标 SVG 生成器服务
进度条图标 SVG 生成器服务
https://github.com/lishengzxc/duing
功能
部署
$ docker build -t duing-image .
$ docker run --rm --name duing -p 3000:3000 duing-image
我在生产环境使用 caddy 来提供稳定的服务!(HTTPS, HTTP/2)
开发
$ npm install
$ npm run dev
贡献
欢迎~
资助
你可以通过 img.lishengcn.cn 得到所有的“ duing ”,如果它为你提供了方便,你或许可以帮助我获得 1 个或者 2 个更好更稳定云服务器。(我的意思并不是说目前不稳定,对于目前的用户来说是稳定的,可能在部署的时候会出现短暂的服务不可用情况。但是我又提供了 200 from cache)
License
MIT License
Copyright (c) 2017 ls
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
很强
很强
当然,这里是一个简单的Node.js服务示例,用于生成带有进度条的SVG图标。我们将使用Express框架来创建这个服务,并动态生成SVG内容。
首先,确保你已经安装了Node.js和npm。然后,创建一个新的项目目录,并初始化npm:
mkdir svg-progress-bar
cd svg-progress-bar
npm init -y
接着,安装Express:
npm install express
然后,在项目目录中创建一个server.js
文件,并添加以下代码:
const express = require('express');
const app = express();
const port = 3000;
app.get('/generate-svg/:progress', (req, res) => {
const progress = parseInt(req.params.progress, 10);
const svgContent = `
<svg width="200" height="20">
<rect width="200" height="20" fill="gray"/>
<rect x="0" y="0" width="${progress * 2}" height="20" fill="green"/>
<text x="10" y="15" font-size="12">${progress}%</text>
</svg>
`;
res.setHeader('Content-Type', 'image/svg+xml');
res.send(svgContent);
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});
启动服务器:
node server.js
现在,你可以访问http://localhost:3000/generate-svg/50
来生成一个50%进度的SVG图标。通过改变URL中的进度值,可以生成不同进度的进度条图标。