-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.js
31 lines (26 loc) · 1.01 KB
/
serve.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const http = require('http');
const Url = require('url');
const ReverseUrl = require('./index.js');
const testUrls = require('./src/testUrls.json');
let html = ``;
html += `<link rel="stylesheet"
href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/default.min.css">`;
html += `<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/highlight.min.js"></script>`;
html += `<script>hljs.initHighlightingOnLoad();</script>`;
testUrls.forEach(url => {
let json = JSON.stringify(ReverseUrl(url));
html += `<b><small>${Url.parse(url).query}</small></b><br>`;
html += `<pre><code class="json">${json}</code></pre>`;
html += '<br><br>';
});
//create a server object:
http
.createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.write(
//JSON.stringify(getUrlParams(testUrl)),
html
); //write a response to the client
res.end(); //end the response
})
.listen(8080); //the server object listens on port 8080