1- import { randomUUID } from "crypto"
2- import { createServer , type IncomingMessage , type ServerResponse } from "http"
1+ import { randomUUID } from "node: crypto"
2+ import { createServer , type IncomingMessage , type ServerResponse } from "node: http"
33
44type GistFormFile = {
55 filename : string
@@ -146,7 +146,8 @@ class Handler {
146146 constructor ( req : IncomingMessage , res : ServerResponse ) {
147147 this . req = req
148148 this . res = res
149- this . origin = `http://${ req . headers . host ?? `localhost:${ PORT } ` } `
149+ const host = req . headers . host ?? `localhost:${ PORT } `
150+ this . origin = `http://${ host } `
150151 this . url = new URL ( req . url ?? "/" , this . origin )
151152 }
152153
@@ -162,7 +163,7 @@ class Handler {
162163 if ( method === "GET" && pathname === "/gists" ) return this . listGists ( )
163164 if ( method === "POST" && pathname === "/gists" ) return this . createGist ( )
164165
165- const gistMatch = pathname . match ( / ^ \/ g i s t s \/ ( [ ^ / ] + ) $ / )
166+ const gistMatch = new RegExp ( / ^ \/ g i s t s \/ ( [ ^ / ] + ) $ / ) . exec ( pathname )
166167 if ( gistMatch ?. [ 1 ] ) {
167168 const gistId = gistMatch [ 1 ]
168169 if ( method === "GET" ) return this . getGist ( gistId )
@@ -171,7 +172,7 @@ class Handler {
171172 if ( method === "DELETE" ) return this . deleteGist ( gistId )
172173 }
173174
174- const rawMatch = pathname . match ( / ^ \/ r a w \/ ( [ ^ / ] + ) \/ ( .+ ) $ / )
175+ const rawMatch = new RegExp ( / ^ \/ r a w \/ ( [ ^ / ] + ) \/ ( .+ ) $ / ) . exec ( pathname )
175176 if ( method === "GET" && rawMatch ?. [ 1 ] && rawMatch ?. [ 2 ] ) {
176177 const gistId = rawMatch [ 1 ]
177178 const filename = decodeURIComponent ( rawMatch [ 2 ] )
0 commit comments