@extendohub/runtime
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -161,3 +161,3 @@ // Load the state for the runtime from a set of well-known environment variables | ||
this.body = value | ||
this.status = this.status || 200 | ||
this._status = this._status || 200 | ||
if (type) this.headers['Content-Type'] = type | ||
@@ -171,3 +171,3 @@ this.headers['Content-Type'] = this.headers['Content-Type'] || 'text/plain' | ||
this.body = value | ||
this.status = this.status || 200 | ||
this._status = this._status || 200 | ||
this.headers['Content-Type'] = 'application/octet-stream' | ||
@@ -180,3 +180,3 @@ return this | ||
this.body = value | ||
this.status = this.status || 200 | ||
this._status = this._status || 200 | ||
this.headers['Content-Type'] = 'application/json' | ||
@@ -195,3 +195,3 @@ return this | ||
this.__used = true | ||
this.status = value | ||
this._status = value | ||
return this | ||
@@ -198,0 +198,0 @@ } |
{ | ||
"name": "@extendohub/runtime", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -15,8 +15,6 @@ import { importFromString } from 'module-from-string' | ||
// if we're not passed any source, assume it's been built in and is at a known location. Just import it. | ||
if (!source) { | ||
// Have to have a separate var to defeat esbuild's import analysis. We expect this code to be loaded at runtime | ||
const path = `../../usercode/index.js` | ||
return import(path) | ||
} | ||
// Since we've been passed some code, load it | ||
if (!source) | ||
return import('../../usercode/index.js') | ||
// Since we've been passed some code, load it | ||
const options = { dirname: process.cwd(), globals: { process, console } } | ||
@@ -47,4 +45,3 @@ const loader = schema || path.extname(codeFile).replace(/^\./, '') | ||
if (params.context.subsystem === 'Pages') { | ||
// Pages typically return html from the function but could manipulate the response directly | ||
const response = params.response || {} | ||
const response = massageResponse(params.response) | ||
if (result) { | ||
@@ -57,4 +54,3 @@ const html = typeof result === 'string' ? result : renderToString(result) | ||
if (params.context.subsystem === 'API') { | ||
// API can return a value directly or manipulate the response. Setting the response takes precedence | ||
const response = params.response || {} | ||
const response = massageResponse(params.response) | ||
if (response.__used) return response | ||
@@ -66,2 +62,12 @@ else return { ...response, body: result, status: 200 } | ||
function massageResponse(response) { | ||
// Requests can return a value directly or manipulate the response. Setting the response takes precedence | ||
response = response || {} | ||
// TODO we used `response.status` with the user to be the `status` function. `_status` is the actual state. | ||
// Here we need to present the state with the good name. There is probably better way to do this but this'll do for now. | ||
response.status = response._status | ||
delete response._status | ||
return response | ||
} | ||
async function invoke(code, params, system) { | ||
@@ -68,0 +74,0 @@ const { debug, schema } = (system || {}) |
11263
254