Skip to content

Commit ba595e0

Browse files
authored
Merge pull request #208 from AthennaIO/develop
chore(response): remove render function
2 parents c4912d6 + 0b9fe31 commit ba595e0

File tree

3 files changed

+8
-66
lines changed

3 files changed

+8
-66
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@athenna/http",
3-
"version": "5.22.0",
3+
"version": "5.23.0",
44
"description": "The Athenna Http server. Built on top of fastify.",
55
"license": "MIT",
66
"author": "João Lenon <lenon@athenna.io>",
@@ -82,7 +82,7 @@
8282
"@athenna/test": "^5.2.0",
8383
"@athenna/tsconfig": "^5.0.0",
8484
"@athenna/view": "^5.1.0",
85-
"@athenna/vite": "^5.9.0",
85+
"@athenna/vite": "^5.10.0",
8686
"@fastify/cors": "^10.0.1",
8787
"@fastify/helmet": "^13.0.0",
8888
"@fastify/rate-limit": "^10.2.1",

src/context/Response.ts

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@
99

1010
import { View } from '@athenna/view'
1111
import type { FastifyReply } from 'fastify'
12-
import { Server } from '#src/facades/Server'
13-
import { Module, Options } from '@athenna/common'
1412
import type { SendOptions } from '@fastify/static'
1513
import type { Request } from '#src/context/Request'
1614
import type { FastifyHelmetOptions } from '@fastify/helmet'
1715

18-
let reactDom = Module.safeImport('react-dom/server') as any
19-
2016
export class Response {
2117
/**
2218
* The fastify response object.
@@ -146,60 +142,6 @@ export class Response {
146142
return this.html(content)
147143
}
148144

149-
/**
150-
* Terminate the request sending a React component to be rendered.
151-
*
152-
* @example
153-
* ```ts
154-
* return response.render('index')
155-
* return response.render('index', {
156-
* component: 'src/resources/app/app.tsx',
157-
* viewData: {},
158-
* beforeComponentRender: (component) => {
159-
* return component.createApp()
160-
* }
161-
* })
162-
* ```
163-
*/
164-
public async render(
165-
view: string,
166-
options?: {
167-
component?: string
168-
viewData?: any
169-
beforeComponentRender?: (componentModule: any) => any
170-
}
171-
) {
172-
if (!reactDom) {
173-
throw new Error(
174-
'React is not installed, please run "npm i react react-dom".'
175-
)
176-
}
177-
178-
reactDom = await reactDom
179-
180-
options = Options.create(options, {
181-
viewData: {},
182-
component: Config.get('http.vite.ssrEntrypoint'),
183-
beforeComponentRender: options?.component
184-
? null
185-
: component => {
186-
return component.createApp(this.request.baseUrl)
187-
}
188-
})
189-
190-
const vite = Server.getVitePlugin().getVite()
191-
let component = await vite.ssrLoadModule(options.component)
192-
193-
if (options.beforeComponentRender) {
194-
component = options.beforeComponentRender(component)
195-
}
196-
197-
return this.view(view, {
198-
element: reactDom.renderToString(component),
199-
...options.viewData
200-
})
201-
}
202-
203145
/**
204146
* Terminate the request sending the response body or not.
205147
*

0 commit comments

Comments
 (0)