Skip to content

Commit

Permalink
seperate index.html from worker.mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidingPlus committed Feb 19, 2025
1 parent 0d8dfdd commit 094c1b8
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cf-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Deploy to Deno Deploy
- name: Deploy to Deno
uses: denoland/deployctl@v1
with:
project: openai-gemini-davidingplus
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"scripts": {
"start": "node node.mjs",
"dev": "nodemon --watch node.mjs --watch src/*.mjs node.mjs",
"start:deno": "deno --allow-env --allow-net deno.mjs",
"dev:deno": "deno --watch --allow-env --allow-net deno.mjs",
"start:deno": "deno --allow-env --allow-net --allow-read deno.mjs",
"dev:deno": "deno --watch --allow-env --allow-net --allow-read deno.mjs",
"start:bun": "bun bun.mjs",
"dev:bun": "bun --watch bun.mjs"
}
}
}
46 changes: 46 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex, nofollow">
<meta charset="utf-8">
</head>

<body>
<p>This is demo instance of <a href="https://github.com/PublicAffairs/openai-gemini">Gemini ➜ OpenAI</a> API transforming proxy!

</br>
Running serverless on <em>Deno</em>.

<p>You can try it with:

<pre id="sample">
curl https://my-openai-gemini-demo.vercel.app/v1/chat/completions \
-H "Authorization: Bearer $YOUR_GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-1.5-pro-latest",
"messages": [{"role": "user", "content": "Hello"}],
"temperature": 0.7
}'
</pre>

<script>
const sampleHref = "https://my-openai-gemini-demo.vercel.app/";
const href = window.location.href;
if (href.startsWith("http") && href.endsWith("/")) {
const sample = document.getElementById("sample");
sample.textContent = sample.textContent.replace(sampleHref, href);
}
</script>

<p>Please deploy your own instance, for free!
</br>
<em>This way, you can keep your API key secure.</em>

<div>
<iframe src="https://ghbtns.com/github-btn.html?user=PublicAffairs&repo=openai-gemini&type=star&count=true" frameborder="0" scrolling="0" width="170" height="30" title="GitHub"></iframe>
</div>

</body>
</html>
57 changes: 5 additions & 52 deletions src/worker.mjs
Original file line number Diff line number Diff line change
@@ -1,57 +1,10 @@
import { Buffer } from "node:buffer";
import { readFileSync } from "node:fs";

const htmlTemplate = `
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex, nofollow">
<meta charset="utf-8">
</head>
<body>
<p>This is demo instance of <a href="https://github.com/PublicAffairs/openai-gemini">Gemini ➜ OpenAI</a> API
transforming proxy!
</br>
Running serverless on <em>Deno</em>.
<p>You can try it with:
<pre id="sample">
curl https://gemini.davidingplus.cn/v1/chat/completions \
-H "Authorization: Bearer $YOUR_GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-1.5-pro-latest",
"messages": [{"role": "user", "content": "Hello"}],
"temperature": 0.7
}'
</pre>
<script>
const sampleHref = "https://gemini.davidingplus.cn/";
const href = window.location.href;
if (href.startsWith("http") && href.endsWith("/")) {
const sample = document.getElementById("sample");
sample.textContent = sample.textContent.replace(sampleHref, href);
}
</script>
<p>Please deploy your own instance, for free!
</br>
<em>This way, you can keep your API key secure.</em>
<div>
<iframe src="https://ghbtns.com/github-btn.html?user=PublicAffairs&repo=openai-gemini&type=star&count=true"
frameborder="0" scrolling="0" width="170" height="30" title="GitHub"></iframe>
</div>
</body>
</html>
`;
const htmlTemplate = readFileSync(
new URL("../public/index.html", import.meta.url),
"utf-8"
);

export default {
async fetch (request) {
Expand Down

0 comments on commit 094c1b8

Please sign in to comment.