Last active
December 14, 2018 23:47
-
-
Save LightSpeedC/6376018 to your computer and use it in GitHub Desktop.
Node.jsによる必要最小限のhttpサーバとhttpsサーバとhttp proxyサーバ ref: https://qiita.com/LightSpeedC/items/3cae342fd7e79a21869f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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