Skip to content

Instantly share code, notes, and snippets.

@alanwei43
alanwei43 / windows-port-proxy.md
Last active April 18, 2024 11:19
windows powershell port forward
netsh interface portproxy add v4tov4 protocol=tcp connectaddress=192.168.67.128 connectport=9091 listenport=9091
@alanwei43
alanwei43 / pipe.js
Created December 29, 2019 01:06
Node HTTP pipe
const http = require("http"),
url = require("url");
http.createServer((proxyReq, proxyRes) => {
console.log(proxyReq.url);
const options = url.parse(proxyReq.url);
const svr = http.request(options, svrRes => {
svrRes.pipe(proxyRes, { end: true });
});
proxyReq.pipe(svr, {
@alanwei43
alanwei43 / typescript-import-json.md
Created January 8, 2020 14:28
import json by typescript

How to import *.json ?

As already answered you need Typescript >= 2.9 and the following settings in tsconfig.json:

{
  "resolveJsonModule": true,
  "esModuleInterop": true,
  "module": "commonjs"
}
@alanwei43
alanwei43 / logger.ts
Created February 12, 2020 12:18
logger module
import { appendFile, existsSync, mkdirSync } from "fs";
import { join } from "path";
let GLOBAL_COUNT = 0;
export class Log {
private dir: string
constructor(private name: string) {
this.dir = join(process.cwd(), "logs");
this.checkDir();
}