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}`); } });