Change image API port, added TLS support, fixed content-type header
This commit is contained in:
parent
871979105c
commit
38e5a1d9f2
6 changed files with 12 additions and 10 deletions
|
@ -55,6 +55,6 @@ RUN npm run build
|
|||
|
||||
USER esmBot
|
||||
|
||||
EXPOSE 8080 8081
|
||||
EXPOSE 3762
|
||||
|
||||
ENTRYPOINT ["node", "api/index.js"]
|
|
@ -1,5 +1,5 @@
|
|||
# esmBot Image API
|
||||
The esmBot image API is a combined HTTP and WebSocket API running on port 8080. The API supports very basic authentication, which is defined on the server via the PASS environment variable and is sent from the client via the Authentication header in both HTTP and WS requests.
|
||||
The esmBot image API is a combined HTTP and WebSocket API running on port 3762. The API supports very basic authentication, which is defined on the server via the PASS environment variable and is sent from the client via the Authentication header in both HTTP and WS requests.
|
||||
|
||||
## HTTP
|
||||
|
||||
|
|
|
@ -196,7 +196,8 @@ httpServer.on("request", async (req, res) => {
|
|||
contentType = "image/webp";
|
||||
break;
|
||||
}
|
||||
res.setHeader("Content-Type", contentType);
|
||||
if (contentType) res.setHeader("Content-Type", contentType);
|
||||
else res.setHeader("Content-Type", ext);
|
||||
const data = jobs.get(id).data;
|
||||
jobs.delete(id);
|
||||
return res.end(data, (err) => {
|
||||
|
@ -230,8 +231,8 @@ httpServer.on("error", (e) => {
|
|||
console.error("An HTTP error occurred: ", e);
|
||||
});
|
||||
|
||||
httpServer.listen(8080, () => {
|
||||
log("HTTP and WS listening on port 8080");
|
||||
httpServer.listen(3762, () => {
|
||||
log("HTTP and WS listening on port 3762");
|
||||
});
|
||||
|
||||
const runJob = (job, ws) => {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
{ "id": "1", "host": "localhost", "port": 2333, "password": "youshallnotpass", "local": true }
|
||||
],
|
||||
"image": [
|
||||
{ "server": "localhost", "auth": "verycoolpass100" }
|
||||
{ "server": "localhost", "auth": "verycoolpass100", "tls": false }
|
||||
],
|
||||
"searx": [
|
||||
"https://searx.xyz"
|
||||
|
|
|
@ -26,6 +26,7 @@ class ImageConnection {
|
|||
constructor(host, auth, tls = false) {
|
||||
this.requests = new Map();
|
||||
this.host = host;
|
||||
this.port = 3762;
|
||||
this.auth = auth;
|
||||
this.tag = null;
|
||||
this.disconnected = false;
|
||||
|
@ -38,7 +39,7 @@ class ImageConnection {
|
|||
} else {
|
||||
this.wsproto = "ws";
|
||||
}
|
||||
this.sockurl = `${this.wsproto}://${host}/sock`;
|
||||
this.sockurl = `${this.wsproto}://${host}:${this.port}/sock`;
|
||||
this.conn = new WebSocket(this.sockurl, {
|
||||
headers: {
|
||||
"Authentication": auth && auth !== "" ? auth : undefined
|
||||
|
@ -50,7 +51,7 @@ class ImageConnection {
|
|||
} else {
|
||||
httpproto = "http";
|
||||
}
|
||||
this.httpurl = `${httpproto}://${host}/image`;
|
||||
this.httpurl = `${httpproto}://${host}:${this.port}/image`;
|
||||
this.conn.on("message", (msg) => this.onMessage(msg));
|
||||
this.conn.once("error", (err) => this.onError(err));
|
||||
this.conn.once("close", () => this.onClose());
|
||||
|
@ -86,7 +87,7 @@ class ImageConnection {
|
|||
}
|
||||
this.requests.clear();
|
||||
if (!this.disconnected) {
|
||||
logger.warn(`Lost connection to ${this.host}, attempting to reconnect in 5 seconds...`);
|
||||
logger.warn(`Lost connection to ${this.host}:${this.port}, attempting to reconnect in 5 seconds...`);
|
||||
await setTimeout(5000);
|
||||
this.conn = new WebSocket(this.sockurl, {
|
||||
headers: {
|
||||
|
|
|
@ -82,7 +82,7 @@ class ImageWorker extends BaseServiceWorker {
|
|||
}
|
||||
|
||||
async connect(server, auth) {
|
||||
const connection = new ImageConnection(`${server}:8080`, auth);
|
||||
const connection = new ImageConnection(server, auth);
|
||||
this.connections.set(server, connection);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue