@athenna/http 5.21.0 → 5.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/context/Response.d.ts +0 -20
- package/src/context/Response.js +0 -42
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/http",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.23.0",
|
|
4
4
|
"description": "The Athenna Http server. Built on top of fastify.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "João Lenon <lenon@athenna.io>",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"@athenna/test": "^5.2.0",
|
|
83
83
|
"@athenna/tsconfig": "^5.0.0",
|
|
84
84
|
"@athenna/view": "^5.1.0",
|
|
85
|
-
"@athenna/vite": "^5.
|
|
85
|
+
"@athenna/vite": "^5.10.0",
|
|
86
86
|
"@fastify/cors": "^10.0.1",
|
|
87
87
|
"@fastify/helmet": "^13.0.0",
|
|
88
88
|
"@fastify/rate-limit": "^10.2.1",
|
|
@@ -103,26 +103,6 @@ export declare class Response {
|
|
|
103
103
|
* ```
|
|
104
104
|
*/
|
|
105
105
|
view(view: string, data?: any): Promise<this>;
|
|
106
|
-
/**
|
|
107
|
-
* Terminate the request sending a React component to be rendered.
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```ts
|
|
111
|
-
* return response.render('index')
|
|
112
|
-
* return response.render('index', {
|
|
113
|
-
* component: 'src/resources/app/app.tsx',
|
|
114
|
-
* viewData: {},
|
|
115
|
-
* beforeComponentRender: (component) => {
|
|
116
|
-
* return component.createApp()
|
|
117
|
-
* }
|
|
118
|
-
* })
|
|
119
|
-
* ```
|
|
120
|
-
*/
|
|
121
|
-
render(view: string, options?: {
|
|
122
|
-
component?: string;
|
|
123
|
-
viewData?: any;
|
|
124
|
-
beforeComponentRender?: (componentModule: any) => any;
|
|
125
|
-
}): Promise<this>;
|
|
126
106
|
/**
|
|
127
107
|
* Terminate the request sending the response body or not.
|
|
128
108
|
*
|
package/src/context/Response.js
CHANGED
|
@@ -7,9 +7,6 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import { View } from '@athenna/view';
|
|
10
|
-
import { Server } from '#src/facades/Server';
|
|
11
|
-
import { Module, Options } from '@athenna/common';
|
|
12
|
-
let reactDom = Module.safeImport('react-dom/server');
|
|
13
10
|
export class Response {
|
|
14
11
|
constructor(response, request) {
|
|
15
12
|
this.response = response;
|
|
@@ -118,45 +115,6 @@ export class Response {
|
|
|
118
115
|
.render(view, data);
|
|
119
116
|
return this.html(content);
|
|
120
117
|
}
|
|
121
|
-
/**
|
|
122
|
-
* Terminate the request sending a React component to be rendered.
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* ```ts
|
|
126
|
-
* return response.render('index')
|
|
127
|
-
* return response.render('index', {
|
|
128
|
-
* component: 'src/resources/app/app.tsx',
|
|
129
|
-
* viewData: {},
|
|
130
|
-
* beforeComponentRender: (component) => {
|
|
131
|
-
* return component.createApp()
|
|
132
|
-
* }
|
|
133
|
-
* })
|
|
134
|
-
* ```
|
|
135
|
-
*/
|
|
136
|
-
async render(view, options) {
|
|
137
|
-
if (!reactDom) {
|
|
138
|
-
throw new Error('React is not installed, please run "npm i react react-dom".');
|
|
139
|
-
}
|
|
140
|
-
reactDom = await reactDom;
|
|
141
|
-
options = Options.create(options, {
|
|
142
|
-
viewData: {},
|
|
143
|
-
component: Config.get('http.vite.ssrEntrypoint'),
|
|
144
|
-
beforeComponentRender: options.component
|
|
145
|
-
? null
|
|
146
|
-
: component => {
|
|
147
|
-
return component.createApp(this.request.baseUrl);
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
const vite = Server.getVitePlugin().getVite();
|
|
151
|
-
let component = await vite.ssrLoadModule(options.component);
|
|
152
|
-
if (options.beforeComponentRender) {
|
|
153
|
-
component = options.beforeComponentRender(component);
|
|
154
|
-
}
|
|
155
|
-
return this.view(view, {
|
|
156
|
-
element: reactDom.renderToString(component),
|
|
157
|
-
...options.viewData
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
118
|
/**
|
|
161
119
|
* Terminate the request sending the response body or not.
|
|
162
120
|
*
|