-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef099a3
commit be530ce
Showing
10 changed files
with
75 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
const { CloudflareRequest } = require('./request.js') | ||
const { CloudflareResponse } = require('./response.js') | ||
module.exports = { CloudflareRequest, CloudflareResponse } | ||
export * from './request.js' | ||
export * from './response.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
const { Request } = require('../src/request.js') | ||
import backend from '../' | ||
|
||
class CloudflareRequest extends Request { } | ||
|
||
module.exports = { CloudflareRequest } | ||
export class CloudflareRequest extends backend.Request { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
const backend = require('../src') | ||
import backend from '..' | ||
|
||
class CloudflareResponse extends backend.Response { | ||
export class CloudflareResponse extends backend.Response { | ||
getResponse() { | ||
const { body, headers, status } = this | ||
|
||
return new Response(body, { headers, status }) | ||
} | ||
} | ||
|
||
module.exports = { CloudflareResponse } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
const { Request, Response, Server, } = require('./src/index.js') | ||
|
||
module.exports = { Request, Response, Server, } | ||
export * from './src/index.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
const { Request } = require('./request.js') | ||
const { Response } = require('./response.js') | ||
const { Server } = require('./server.js') | ||
|
||
module.exports = { Request, Response, Server, } | ||
export * from './request.js' | ||
export * from './response.js' | ||
export * from './router.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,43 @@ | ||
class Request { } | ||
|
||
module.exports = { Request } | ||
export class Request { | ||
method = null | ||
path = null | ||
queries = {} | ||
heders = new Headers() | ||
body = '' | ||
json = {} | ||
|
||
constructor(buffer = '') { | ||
const chunk = buffer.toString() | ||
this.method = this.parseMethod(chunk) | ||
this.path = this.parsePath(chunk) | ||
this.queries = this.parseQueries(chunk) | ||
this.headers = this.parseHeaders(chunk) | ||
this.body = this.parseBody(chunk) | ||
this.json = this.parseJSON(chunk) | ||
} | ||
|
||
parseMethod(chunk) { | ||
return 'GET' | ||
} | ||
|
||
parsePath(chunk) { | ||
return '/' | ||
} | ||
|
||
parseQueries(chunk) { | ||
return {} | ||
} | ||
|
||
parseHeaders(chunk) { | ||
return new Headers() | ||
} | ||
|
||
parseBody(chunk) { | ||
return '{}' | ||
} | ||
|
||
parseJSON(chunk) { | ||
return JSON.parse(this.parseBody(chunk)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export class Router { | ||
requests = [] | ||
|
||
request(method = 'GET', path = '/', fn = (() => { })) { | ||
this.requests.push({ method, path, fn }) | ||
|
||
return this | ||
} | ||
|
||
get(path = '/', fn = (() => {})) { | ||
return this.request('GET', path, fn) | ||
} | ||
|
||
post(path = '/', fn = (() => {})) { | ||
return this.request('POST', path, fn) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters