File tree Expand file tree Collapse file tree 5 files changed +54
-2
lines changed Expand file tree Collapse file tree 5 files changed +54
-2
lines changed Original file line number Diff line number Diff line change 27
27
}
28
28
],
29
29
"rewrites" : [
30
+ {
31
+ "source" : " /api/*" ,
32
+ "function" : " hono_server" ,
33
+ "region" : " asia-northeast1"
34
+ },
30
35
{
31
36
"source" : " **" ,
32
37
"destination" : " /index.html"
Original file line number Diff line number Diff line change 16
16
"main" : " lib/index.js" ,
17
17
"dependencies" : {
18
18
"firebase-admin" : " ^11.11.0" ,
19
- "firebase-functions" : " ^4.4.1"
19
+ "firebase-functions" : " ^4.4.1" ,
20
+ "hono" : " ^3.11.9"
20
21
},
21
22
"devDependencies" : {
22
23
"@typescript-eslint/eslint-plugin" : " ^6.4.1" ,
Original file line number Diff line number Diff line change
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 ) ;
Original file line number Diff line number Diff line change @@ -10,4 +10,6 @@ import exportIfNeeded from "./common/exportifneeded";
10
10
// response.send("Hello from Firebase!");
11
11
// });
12
12
13
- exportIfNeeded ( "test" , "tests/test" , exports ) ;
13
+ // exportIfNeeded("test", "tests/test", exports);
14
+
15
+ exportIfNeeded ( "hono_server" , "server/hono" , exports ) ;
Original file line number Diff line number Diff line change
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 ) ;
You can’t perform that action at this time.
0 commit comments