|
|
@@ -1,4 +1,5 @@ |
|
|
|
import http, { createServer as httpCreateServer } from 'http'; |
|
|
|
import { HTTPParser } from 'http-parser-js'; |
|
|
|
import { createServer as httpCreateSecureServer } from 'https'; |
|
|
|
import {constants,} from 'http2'; |
|
|
|
import * as v from 'valibot'; |
|
|
@@ -195,6 +196,7 @@ export const createServer = (backendState: BackendState, serverParams = {} as Cr |
|
|
|
const isHttps = 'key' in serverParams && 'cert' in serverParams; |
|
|
|
const theRes = new CqrsEventEmitter(); |
|
|
|
|
|
|
|
http.METHODS.push('QUERY'); |
|
|
|
const server = isHttps |
|
|
|
? httpCreateSecureServer({ |
|
|
|
key: serverParams.key, |
|
|
@@ -780,6 +782,54 @@ export const createServer = (backendState: BackendState, serverParams = {} as Cr |
|
|
|
)(reqRaw, res); |
|
|
|
}; |
|
|
|
|
|
|
|
// server.on('connection', (socket) => { |
|
|
|
// if (!HTTPParser.methods.includes('QUERY')) { |
|
|
|
// HTTPParser.methods.push('QUERY'); |
|
|
|
// } |
|
|
|
// const httpParserMut = (HTTPParser as unknown as Record<string, unknown>); |
|
|
|
// console.log(httpParserMut.methods); |
|
|
|
// httpParserMut.socket = socket; |
|
|
|
// httpParserMut.remove = () => { |
|
|
|
// // noop |
|
|
|
// }; |
|
|
|
// httpParserMut.free = () => { |
|
|
|
// // noop |
|
|
|
// }; |
|
|
|
// socket.parser = httpParserMut; |
|
|
|
// }); |
|
|
|
|
|
|
|
// server.on('connection', (socket) => { |
|
|
|
// let newLineOffset; |
|
|
|
// let receiveBuffer = Buffer.from(''); |
|
|
|
// const listeners = socket.listeners('data'); |
|
|
|
// const oldListener = listeners[0]; |
|
|
|
// |
|
|
|
// function newListener(this: any, d, start, end) { |
|
|
|
// console.log(d.slice(start, end).toString('utf-8')); |
|
|
|
// |
|
|
|
// receiveBuffer = Buffer.concat([receiveBuffer, d.slice(start, end)]); |
|
|
|
// if ((newLineOffset = receiveBuffer.toString('ascii').indexOf('\n')) > -1) { |
|
|
|
// var firstLineParts = receiveBuffer.slice(0, newLineOffset).toString().split(' '); |
|
|
|
// firstLineParts[0] = firstLineParts[0].replace(/^QUERY$/ig, 'POST'); |
|
|
|
// //firstLineParts[2] = firstLineParts[2].replace(/^ICE\//ig, 'HTTP/'); |
|
|
|
// receiveBuffer = Buffer.concat([ |
|
|
|
// Buffer.from( |
|
|
|
// firstLineParts.join(' ') + '\r\n' + |
|
|
|
// 'Content-Length: 9007199254740992\r\n' |
|
|
|
// ), |
|
|
|
// receiveBuffer.slice(newLineOffset + 1) |
|
|
|
// ]); |
|
|
|
// } |
|
|
|
// |
|
|
|
// console.log(receiveBuffer.toString('utf-8')); |
|
|
|
// oldListener.apply(this, d); |
|
|
|
// } |
|
|
|
// |
|
|
|
// socket.on('data', newListener); |
|
|
|
// socket.off('data', oldListener); |
|
|
|
// }); |
|
|
|
|
|
|
|
// TODO create server directly from net.createConnection() |
|
|
|
server.on('request', handleRequest); |
|
|
|
|
|
|
|
return { |
|
|
|