-
-
Save YuriiSerdiuk/9dc3836595113ac9b9f063f60eb09dfe to your computer and use it in GitHub Desktop.
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'); | |
const https = require('https'); | |
const fs = require('fs'); | |
const {JSDOM} = require('jsdom'); | |
const PORT =8000; | |
const urlMap = { | |
'/img/' : ()=> { | |
return fs.readFileSync('./index.html'); | |
}, | |
'/users/' : ()=> 'user : admin \n user : Vasia', | |
'/posts/':()=>{} | |
}; | |
const getRaw = (index2) => { | |
return new Promise((resolve, reject) => { | |
let raw = ''; | |
https.get(index2, (res) => { | |
res.on('data', (chunk) => { | |
raw += chunk; | |
}); | |
res.on("end", () => { | |
resolve(raw); | |
}) | |
}) | |
}).then((raw)=>{ | |
console.log(raw); | |
}); | |
}; | |
const server = http.createServer((request,response) => { | |
let ind = request.url.split('='); | |
let index2 = ind[1]; | |
getRaw(index2); | |
debugger; | |
const url = request.url; | |
if (url in urlMap ){ | |
response.write(urlMap[url]()); | |
}else { | |
response.write('404 not found link'); | |
} | |
response.end(); | |
} ).listen(PORT); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment