Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSL support #701

Closed
ivanfioravanti opened this issue Oct 4, 2023 · 4 comments
Closed

SSL support #701

ivanfioravanti opened this issue Oct 4, 2023 · 4 comments
Labels
feature request New feature or request

Comments

@ivanfioravanti
Copy link

Hi super Ollama team!
I received an interest comment on the chatbot-ollama interface here.
It seems that sharing a server and connect from multiple clients works, but it's plain HTTP.
Adding SSL can help in this scenario.

@ivanfioravanti
Copy link
Author

Clearly there is always the easy way to have something in front of Ollama, but I was just wondering if this can make sense

@montoulieu
Copy link

Yeah +1.
SSL support would be a great addition.

@Clivern
Copy link

Clivern commented Oct 5, 2023

It uses gin so RunTLS can be used I think
https://github.com/gin-gonic/gin/blob/master/docs/doc.md?plain=1#L2032-L2051

@jmorganca jmorganca added the feature request New feature or request label Oct 28, 2023
@jmorganca jmorganca changed the title Any plans on adding SSL support? SSL support Oct 28, 2023
@thesourmango
Copy link

thesourmango commented Nov 1, 2023

Had the same issue and found this thread. I'm not familiar with gin and RunTLS so I used an express server as middleware. Thought I could share the server file since it's so dead simple someone might have use of it :)

On the front-end I call the middleware express server on https://yourdomain.com/api/
const res = await fetch("https://yourdomain.com/api/", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ "question": query })
});

On the middleware express API I get the response via https, i forward it to ollama as http and return the response as https. No more browser complaints ;)

Heres the code for the middleware API
const express = require("express");
const https = require("https");
const fs = require("fs");
const path = require("path");

const app = express();
const port = 443;
app.use(express.static('public')) // For serving static files from public folder.
app.use(express.json()); // For parsing application/json

// Routes
app.post("/api/", async (req, res) => {
// Send message to Model API
const response = await fetch("http://localhost:11434/api/generate", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ "model": "zephyr", "prompt": req.body.question})
});
// Return stream of Uint8Array
for await (const chunk of response.body) {
res.write(chunk); // took me ages to find this oh so obvious method!
}

});

// Read SSL certificate and key files
const options = {
// Replace these with location of servers certificates
key: fs.readFileSync("./privkey.pem"),
cert: fs.readFileSync("./fullchain.pem"),
};

// Create HTTPS server
const server = https.createServer(options, app);

server.listen(port, () => {
console.log(App listening on https://localhost:${port});
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants