|
const express = require('express'); |
|
const bodyparser = require('body-parser'); |
|
const txt2image = require("./txt2images") |
|
const fs = require('fs'); |
|
|
|
|
|
const PORT = 7860; |
|
const HOST = '0.0.0.0'; |
|
|
|
|
|
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'); |
|
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'); |
|
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}`); |
|
} |
|
|
|
}); |