Skip to content

Commit

Permalink
Merge pull request #45 from ItzNotABug/fix-broken-view-engines
Browse files Browse the repository at this point in the history
Fix Broken View Engines
  • Loading branch information
ItzNotABug authored Oct 4, 2024
2 parents 30ad8b0 + 34e38f5 commit cad09fa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
2 changes: 1 addition & 1 deletion source/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@itznotabug/appexpress",
"version": "1.6.1",
"version": "1.6.2",
"description": "An `express.js` like framework for Appwrite Functions, enabling super-easy navigation!",
"author": "@itznotabug",
"type": "module",
Expand Down
12 changes: 5 additions & 7 deletions source/tests/utils/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ export const createContext = ({
*/
res: {
text: function (body, statusCode = 200, headers = {}) {
// open-runtimes uses below logic, but it fails our tests -
// return this.binary(Buffer.from(body, "utf8"), statusCode, headers);
return {
body: body,
statusCode: statusCode,
headers: headers,
};
return this.binary(
Buffer.from(body, 'utf8').toString(),
statusCode,
headers,
);
},
binary: function (bytes, statusCode = 200, headers = {}) {
return {
Expand Down
21 changes: 5 additions & 16 deletions source/types/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class AppExpressResponse {
}

this.#customHeaders['content-type'] = contentType;
this.#wrapForPromise(promise, statusCode, true);
this.#wrapForPromise(promise, statusCode);
} catch (error) {
this.#context.error(`Failed to read HTML file: ${error}`);
this.text('Internal Server Error', 500, 'text/plain');
Expand Down Expand Up @@ -270,22 +270,11 @@ class AppExpressResponse {
*
* @param {Promise<any>} promise - Promise that returns a html string on completion.
* @param {number} statusCode=200 - The HTTP status code.
* @param {boolean} isBinary=false - Whether the content/promise has a binary type.
*/
#wrapForPromise(promise, statusCode, isBinary = false) {
let responseMethod = isBinary ? 'binary' : 'text';
/**
* fun-fact: `text` uses `binary` internally!
*
* text: `this.binary((Buffer.from(body, "utf8"), statusCode, headers).`
*/
let promiseDataType = this.#response[responseMethod](
promise,
statusCode,
{
...this.#customHeaders,
},
);
#wrapForPromise(promise, statusCode) {
let promiseDataType = this.#response.binary(promise, statusCode, {
...this.#customHeaders,
});

this.#wrapReturnForSource(promiseDataType);
}
Expand Down

0 comments on commit cad09fa

Please sign in to comment.