Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Node.jsによる必要最小限のhttpサーバとhttpsサーバとhttp proxyサーバ ref: https://qiita.com/LightSpeedC/items/3cae342fd7e79a21869f
const http = require('http'), url = require('url');
http.createServer((cliReq, cliRes) => {
const x = url.parse(cliReq.url);
const opt = {host: x.hostname, port: x.port || 80, path: x.path,
method: cliReq.method, headers: cliReq.headers};
const svrReq = http.request(opt, svrRes => {
cliRes.writeHead(svrRes.statusCode, svrRes.headers);
svrRes.pipe(cliRes); });
cliReq.pipe(svrReq);
}).listen(8080);
const http = require('http');
http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(3000, () => console.log('Server http://localhost:3000'));
const https = require('https'), fs = require('fs');
const options = {pfx: fs.readFileSync('secure.pfx'),
passphrase: 'passphrase'};
https.createServer(options, (req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(3000, () => console.log('Server https://localhost:3000'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.