Created
July 15, 2019 07:03
-
-
Save buroz/a1c9de6c843ac9004fa3c09064060aa8 to your computer and use it in GitHub Desktop.
template engine
This file contains hidden or 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
<h1><strong style="color:red">Reponse Port : </strong>8003</h1> | |
<p><strong style="color:red">METHOD: </strong>{{method}}</p> | |
<p><strong style="color:red">URL: </strong>{{url}}</p> | |
<p><strong style="color:red">Req HTTP Version: </strong>{{version}}</p> |
This file contains hidden or 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 render = (str, o) => { | |
const keys = Object.keys(o) | |
keys.forEach(c => { | |
let field = "{{" + c + "}}" | |
let changedOne = field.replace(field, o[c]) | |
str = str.replace(field, changedOne) | |
}) | |
return str | |
} | |
const fileStr = readFileSync("index.html", "utf-8") | |
const rendered = render(fileStr, { | |
method: headers[http2.constants.HTTP2_HEADER_METHOD], | |
url: headers[http2.constants.HTTP2_HEADER_PATH], | |
version: "2", | |
port: 8003 | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment