-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: import code from monorepo (#25)
adds new http lib adds iso textencoder shim plus tests
- Loading branch information
1 parent
201b718
commit dcd6f77
Showing
11 changed files
with
517 additions
and
22 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict' | ||
|
||
const { promisify } = require('util') | ||
const http = require('http') | ||
const url = require('url') | ||
const querystring = require('querystring') | ||
|
||
const echoServer = async (port = 3000) => { | ||
const server = http.createServer() | ||
|
||
server.on('request', (request, response) => { | ||
try { | ||
|
||
const uri = url.parse(request.url) | ||
const qs = uri.query ? querystring.parse(uri.query) : {} | ||
const status = qs.status || 200 | ||
const contentType = qs.contentType || 'text/plain' | ||
|
||
const headers = { | ||
'Access-Control-Allow-Origin': '*' | ||
} | ||
|
||
if (qs.body) { | ||
headers['Content-Type'] = contentType | ||
headers['Content-Length'] = qs.body.length | ||
} | ||
|
||
response.writeHead(status, headers) | ||
|
||
if (qs.body) { | ||
response.end(qs.body) | ||
} else { | ||
request.pipe(response) | ||
} | ||
|
||
} catch (err) { | ||
console.error(err) | ||
} | ||
}) | ||
|
||
await promisify(server.listen.bind(server))(port) | ||
|
||
return { | ||
stop: promisify(server.close.bind(server)) | ||
} | ||
} | ||
|
||
let echo | ||
|
||
module.exports = { | ||
hooks: { | ||
pre: async () => { | ||
echo = await echoServer() | ||
}, | ||
post: async () => { | ||
await echo.stop() | ||
} | ||
} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
'use strict' | ||
|
||
const { default: ky } = require('ky-universal') | ||
const toIterable = require('stream-to-it/source') | ||
const Http = require('../http') | ||
|
||
module.exports = async function * urlSource (url, options) { | ||
options = options || {} | ||
|
||
const { body } = await ky.get(url) | ||
const http = new Http() | ||
|
||
yield { | ||
path: decodeURIComponent(new URL(url).pathname.split('/').pop() || ''), | ||
content: toIterable(body) | ||
content: await http.iterator(url, { method: 'get' }) | ||
} | ||
} |
Oops, something went wrong.