Spaces:
Sleeping
Sleeping
T1ckbase
commited on
Commit
·
54ba1c5
1
Parent(s):
763a3d5
first commit
Browse files- .vscode/settings.json +6 -0
- Dockerfile +14 -0
- README.md +1 -1
- deno.json +16 -0
- deno.lock +16 -0
- main.ts +23 -0
.vscode/settings.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"deno.enable": true,
|
| 3 |
+
"deno.lint": true,
|
| 4 |
+
"editor.formatOnSave": true,
|
| 5 |
+
"editor.defaultFormatter": "denoland.vscode-deno"
|
| 6 |
+
}
|
Dockerfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM denoland/deno:latest
|
| 2 |
+
|
| 3 |
+
EXPOSE 7860
|
| 4 |
+
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Prefer not to run as root.
|
| 8 |
+
USER deno
|
| 9 |
+
|
| 10 |
+
COPY . /app
|
| 11 |
+
|
| 12 |
+
RUN deno install --entrypoint main.ts
|
| 13 |
+
|
| 14 |
+
CMD ["run", "-A", "main.ts"]
|
README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
---
|
| 2 |
title: Susface Api
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: green
|
| 6 |
sdk: docker
|
|
|
|
| 1 |
---
|
| 2 |
title: Susface Api
|
| 3 |
+
emoji: 🤨
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: green
|
| 6 |
sdk: docker
|
deno.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"tasks": {
|
| 3 |
+
"dev": "deno --allow-net --allow-read --allow-env --watch main.ts"
|
| 4 |
+
},
|
| 5 |
+
"imports": {
|
| 6 |
+
"@hono/hono": "jsr:@hono/hono@^4.7.1"
|
| 7 |
+
},
|
| 8 |
+
"fmt": {
|
| 9 |
+
"indentWidth": 2,
|
| 10 |
+
"lineWidth": 69420,
|
| 11 |
+
"proseWrap": "preserve",
|
| 12 |
+
"semiColons": true,
|
| 13 |
+
"singleQuote": true,
|
| 14 |
+
"useTabs": false
|
| 15 |
+
}
|
| 16 |
+
}
|
deno.lock
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"version": "4",
|
| 3 |
+
"specifiers": {
|
| 4 |
+
"jsr:@hono/hono@^4.7.1": "4.7.1"
|
| 5 |
+
},
|
| 6 |
+
"jsr": {
|
| 7 |
+
"@hono/hono@4.7.1": {
|
| 8 |
+
"integrity": "f75aaf6a026ad05406e60125a70a3d2a77e3b62991f8c4e38c624bdfc1a1dc26"
|
| 9 |
+
}
|
| 10 |
+
},
|
| 11 |
+
"workspace": {
|
| 12 |
+
"dependencies": [
|
| 13 |
+
"jsr:@hono/hono@^4.7.1"
|
| 14 |
+
]
|
| 15 |
+
}
|
| 16 |
+
}
|
main.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Hono } from '@hono/hono';
|
| 2 |
+
import { logger } from '@hono/hono/logger';
|
| 3 |
+
|
| 4 |
+
// https://api-inference.huggingface.co/v1
|
| 5 |
+
const HF_API_URL = 'https://api-inference.huggingface.co';
|
| 6 |
+
|
| 7 |
+
const app = new Hono();
|
| 8 |
+
|
| 9 |
+
app.use(logger());
|
| 10 |
+
app.get('/', (c) => c.text('Hello Hono!'));
|
| 11 |
+
|
| 12 |
+
app.post('*', async (c) => {
|
| 13 |
+
const url = new URL(c.req.url);
|
| 14 |
+
const targetPath = url.pathname + url.search;
|
| 15 |
+
const targetUrl = `${HF_API_URL}${targetPath}`;
|
| 16 |
+
return await fetch(targetUrl, {
|
| 17 |
+
method: 'POST',
|
| 18 |
+
headers: c.req.raw.headers,
|
| 19 |
+
body: c.req.raw.body,
|
| 20 |
+
});
|
| 21 |
+
});
|
| 22 |
+
|
| 23 |
+
Deno.serve({ port: 7860 }, app.fetch);
|