Last active
March 4, 2019 18:19
-
-
Save gokaybiz/e249de4be95083e2890330fc928146d0 to your computer and use it in GitHub Desktop.
Simple nodejs http server and api request
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
let log = console.log, | |
port = process.env.port || 8081 | |
const http = require("http"), | |
web = http.createServer( | |
(req, res) => { | |
log(`Istek geldi: |${req.method}| ${req.url}`) | |
if (req.url == '/uzat') { | |
let todos = http.request({ | |
host: "jsonplaceholder.typicode.com", | |
path: "/todos/1" | |
}, (resp) => { | |
resp.setEncoding('utf8') | |
resp.on('data', | |
(chunk) => { | |
res.setHeader('content-type', 'application/json') | |
res.write(chunk) | |
res.end() | |
} | |
) | |
} | |
) | |
todos.end() | |
} else { | |
res.setHeader('content-type', 'text/html; charset=utf-8'); | |
res.write("go fuck yourself anam? <a href" + '="/uzat"> ' + "TIKLA</a>") | |
res.end() | |
} | |
} | |
) | |
web.listen(port, | |
() => { | |
log(`http://127.0.0.1:${port} adresinde calisiyor anam!`) | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment