File size: 1,210 Bytes
44f12da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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}`);
    }

});