Download server.js from zh21608/nodejs: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/spaces/zh21608/nodejs/resolve/main/server.js
- Command line
-
hf download hf://spaces/zh21608/nodejs/server.js
-
curl -L -o server.js https://huggingface.co/spaces/zh21608/nodejs/resolve/main/server.js
1.21 kB
| const express = require('express'); | |
| const bodyparser = require('body-parser'); | |
| const txt2image = require("./txt2images") | |
| const fs = require('fs'); //引入fs模块 | |
| // Constants | |
| const PORT = 7860; | |
| const HOST = '0.0.0.0'; | |
| // App | |
| const app = express(); | |
| app.use(bodyparser.urlencoded({ extended: true })) | |
| app.post("/txt2pic", async (req, res) => { | |
| var prompt = req.body.prompt; | |
| var size = req.body.size; | |
| var url = await txt2image.txt2img(prompt, size) | |
| res.send(url) | |
| }) | |
| app.get('/', (req, res) => { | |
| res.writeHead(200, { 'Content-Type': 'text/html' }) | |
| var html = fs.readFileSync(__dirname + '/static/index.html', 'utf-8'); //读取html文件,__dirname表示当前文件所在的目录路径 | |
| res.end(html); | |
| }); | |
| app.get('/jquery', (req, res) => { | |
| res.writeHead(200, { "Content-Type": "application/javascript" }) | |
| var js = fs.readFileSync(__dirname + '/static/jquery.js', 'utf-8'); //读取jquery文件,__dirname表示当前文件所在的目录路径 | |
| res.end(js); | |
| }); | |
| app.listen(PORT, HOST, () => { | |
| if (HOST == '0.0.0.0') { | |
| console.log(`Running on http://127.0.0.1:${PORT}`); | |
| } else { | |
| console.log(`Running on http://${HOST}:${PORT}`); | |
| } | |
| }); |