jai-server
Version:
Fast , simple and powerful web framework for creating REST APIs for your next project. RESTFul API server
19 lines (16 loc) • 703 B
text/typescript
import { IncomingMessage } from 'http';
import {RequestObject} from '../../types/types';
import { JaiServerConfig } from '../../types/types';
function AddRequestPrototype(req: IncomingMessage, config: JaiServerConfig): void {
const extendedReq = req as RequestObject;
extendedReq.body = {};
const { host } = req.headers;
const parsedUrl = new URL(`http://${host}${req.url}`);
extendedReq.protocol = config.protocol;
extendedReq.path = parsedUrl.pathname;
extendedReq.host = config.host;
extendedReq.port = config.port;
extendedReq.query = Object.fromEntries(parsedUrl.searchParams);
extendedReq.ip = (req.socket.remoteAddress as string);
}
export default AddRequestPrototype;