Skip to content

Commit 1830cb1

Browse files
committed
Merge branch 'main' of github.com:isamu/firebase-vue3-startup-kit
2 parents 9c97222 + be2a752 commit 1830cb1

File tree

5 files changed

+54
-2
lines changed

5 files changed

+54
-2
lines changed

firebase.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
}
2828
],
2929
"rewrites": [
30+
{
31+
"source": "/api/*",
32+
"function": "hono_server",
33+
"region": "asia-northeast1"
34+
},
3035
{
3136
"source": "**",
3237
"destination": "/index.html"

functions/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"main": "lib/index.js",
1717
"dependencies": {
1818
"firebase-admin": "^11.11.0",
19-
"firebase-functions": "^4.4.1"
19+
"firebase-functions": "^4.4.1",
20+
"hono": "^3.11.9"
2021
},
2122
"devDependencies": {
2223
"@typescript-eslint/eslint-plugin": "^6.4.1",
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Hono } from "hono";
2+
import { Request as FunctionRequest, Response } from "firebase-functions";
3+
4+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5+
const handle = (app: Hono<any>) => {
6+
return async (req: FunctionRequest, resp: Response) => {
7+
const url = new URL(`${req.protocol}://${req.hostname}${req.url}`);
8+
9+
const headers = new Headers()
10+
11+
Object.keys(req.headers).forEach((k) => {
12+
headers.set(k, req.headers[k] as string);
13+
})
14+
const body = req.body;
15+
16+
const newRequest = ["GET", "HEAD"].includes(req.method) ? new Request(url, {
17+
headers,
18+
method: req.method,
19+
}) : new Request(url, {
20+
headers,
21+
method: req.method,
22+
body,
23+
})
24+
const res = await app.fetch(newRequest);
25+
resp.json(await res.json());
26+
};
27+
};
28+
29+
const app = new Hono();
30+
31+
app.get("/api/test", (c) => c.json({message: "Hono!"}));
32+
33+
export const server = handle(app);

functions/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ import exportIfNeeded from "./common/exportifneeded";
1010
// response.send("Hello from Firebase!");
1111
// });
1212

13-
exportIfNeeded("test", "tests/test", exports);
13+
// exportIfNeeded("test", "tests/test", exports);
14+
15+
exportIfNeeded("hono_server", "server/hono", exports);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as functions from "firebase-functions";
2+
import * as hono from "../../functions/server/hono";
3+
4+
export default functions
5+
.region("asia-northeast1")
6+
.runWith({
7+
maxInstances: 5,
8+
timeoutSeconds: 10,
9+
memory: "1GB" as "1GB",
10+
})
11+
.https.onRequest(hono.server);

0 commit comments

Comments
 (0)