-
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.
- uses aegir test helps - updates deps - adds more tests Co-authored-by: Alex Potsides <[email protected]>
- Loading branch information
1 parent
34dc3c9
commit 070a456
Showing
14 changed files
with
71 additions
and
108 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 |
---|---|---|
@@ -1,59 +1,21 @@ | ||
'use strict' | ||
|
||
const { promisify } = require('util') | ||
const http = require('http') | ||
const url = require('url') | ||
const querystring = require('querystring') | ||
const EchoServer = require('aegir/utils/echo-server') | ||
const { format } =require('iso-url') | ||
|
||
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 | ||
let echo = new EchoServer() | ||
|
||
module.exports = { | ||
hooks: { | ||
pre: async () => { | ||
echo = await echoServer() | ||
const server = await echo.start() | ||
const { address, port } = server.server.address() | ||
return { | ||
env: { ECHO_SERVER : format({ protocol: 'http:', hostname: address, port })} | ||
} | ||
}, | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
'use strict' | ||
|
||
const nanoid = require('nanoid') | ||
const { nanoid } = require('nanoid') | ||
|
||
/** | ||
* Temporary folder | ||
|
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
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
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 was deleted.
Oops, something went wrong.