Skip to content

Instantly share code, notes, and snippets.

@aweber1
aweber1 / parseRequestUrl.js
Created April 4, 2020 12:16
Node.js parse request url
import { IncomingMessage } from 'http';
import { TLSSocket } from 'tls';
import { URL } from 'url';
export function parseRequestUrl(req: IncomingMessage) {
let protocol = 'http';
if ((req.socket as TLSSocket).encrypted) {
protocol = 'https';
}
@zh
zh / server.js
Created April 13, 2011 08:16 — forked from sintaxi/server.js
simple reverse proxy with node.js
var http = require("http"),
util = require("util")
http.createServer(function(req, rsp){
var regex = /^\/(v1|v2)/g
var matches = req.url.match(regex)
if((matches && matches[0] === "/v1") || (req.headers["x-api-version"] === "v1"))
var port = 8001