Implements most platform-independent features

This commit is contained in:
2022-06-28 16:22:49 +00:00
committed by GitHub
parent ee091206b3
commit f3c0d646e3
18 changed files with 584 additions and 0 deletions

7
src/platform/index.ts Normal file
View File

@ -0,0 +1,7 @@
import { request, response } from "../interface";
export interface PlatformAdapater<T = any, K = any> {
listen(port: number): void;
handleRequest(request: any): request<T>;
handleResponse(response: response<K>, NativeResponse?: any): any;
}

27
src/platform/node.ts Normal file
View File

@ -0,0 +1,27 @@
import { PlatformAdapater } from ".";
import { request, response } from "../interface";
import router from "../router";
import http from "http";
export class NodePlatformAdapter<T = any, K = any> implements PlatformAdapater {
constructor(Router: )
listen(port: number): void {
const server = http.createServer();
server.on(
"request",
(req: http.IncomingMessage, res: http.ServerResponse) => {
const request = this.handleRequest(req);
}
);
server.listen(port);
}
handleRequest(request: http.IncomingMessage): request<T> {
throw new Error("Method not implemented.");
}
handleResponse(response: response<K>, NativeResponse: http.ServerResponse) {
throw new Error("Method not implemented.");
}
}