alan-js-runtime
Advanced tools
Comparing version 0.1.28 to 0.1.29
25
index.js
@@ -927,7 +927,14 @@ require('cross-fetch/polyfill') | ||
// IO opcodes | ||
httpget: async url => { | ||
httpreq: async req => { | ||
const [ method, url, headers, body, ] = req | ||
try { | ||
const response = await fetch(url) | ||
const result = await response.text() | ||
return [ true, result ] | ||
const response = await fetch(url, { | ||
method, | ||
headers, | ||
body: body.length > 0 ? body : undefined, | ||
}); | ||
const rstatus = response.status | ||
const rheaders = Object.entries(response.headers) | ||
const rbody = await response.text() | ||
return [ true, [ rstatus, rheaders, rbody, 0n ] ] | ||
} catch (e) { | ||
@@ -937,11 +944,2 @@ return [ false, e.toString() ] | ||
}, | ||
httppost: async (url, body) => { | ||
try { | ||
const response = await fetch(url, { method: 'POST', body }) | ||
const result = await response.text() | ||
return [ true, result ] | ||
} catch (e) { | ||
return [ false, e.toString() ] | ||
} | ||
}, | ||
httplsn: async (port) => { | ||
@@ -960,2 +958,3 @@ const server = http.createServer((req, res) => { | ||
e.emit('__conn', [ | ||
req.method, | ||
req.url, | ||
@@ -962,0 +961,0 @@ Object.entries(req.headers), |
{ | ||
"name": "alan-js-runtime", | ||
"version": "0.1.28", | ||
"version": "0.1.29", | ||
"description": "The runtime component for alan-js. Separately licensed from the compiler.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
41531
3
957