Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 116c43f

Browse files
committed
fix(server): fix server app init method
1 parent 64241d9 commit 116c43f

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

server/app.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export class Application implements ServerApplication {
9292
Deno.env.set('ALEPH_VERSION', VERSION)
9393
Deno.env.set('BUILD_MODE', this.mode)
9494

95+
const alephPkgUri = getAlephPkgUri()
9596
const buildManifestFile = path.join(this.buildDir, 'build.manifest.json')
9697
const configHash = computeHash(JSON.stringify({
9798
...this.defaultCompileOptions,
@@ -139,16 +140,23 @@ export class Application implements ServerApplication {
139140
const { init } = await import(`../framework/${this.config.framework}/init.ts`)
140141
await init(this)
141142

143+
// import framework renderer
144+
if (this.config.ssr) {
145+
const { jsFile } = await this.compile(`${alephPkgUri}/framework/${this.config.framework}/renderer.ts`)
146+
const { render } = await import(`file://${jsFile}`)
147+
if (util.isFunction(render)) {
148+
this.#renderer.setFrameworkRenderer({ render })
149+
}
150+
}
151+
142152
log.info('Compiling...')
143153

144154
// pre-compile framework modules
145-
const alephPkgUri = getAlephPkgUri()
146-
await Promise.all<any>([
147-
this.compile(`${alephPkgUri}/framework/${this.config.framework}/bootstrap.ts`),
148-
this.isDev ? this.compile(`${alephPkgUri}/framework/core/hmr.ts`) : Promise.resolve(),
149-
this.isDev ? this.compile(`${alephPkgUri}/framework/core/nomodule.ts`) : Promise.resolve(),
150-
this.config.ssr ? this.#renderer.load() : Promise.resolve()
151-
])
155+
await this.compile(`${alephPkgUri}/framework/${this.config.framework}/bootstrap.ts`)
156+
if (this.isDev) {
157+
await this.compile(`${alephPkgUri}/framework/core/hmr.ts`)
158+
await this.compile(`${alephPkgUri}/framework/core/nomodule.ts`)
159+
}
152160

153161
// compile custom components
154162
for (const name of ['app', '404', 'loading']) {

server/bundler.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ export class Bundler {
6767
}
6868
})
6969

70-
console.log(remoteEntries)
71-
console.log(sharedEntries)
72-
console.log(entries)
73-
74-
7570
await Promise.all([
7671
// this.createPolyfillBundle(),
7772
this.createBundleChunk(

server/ssr.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import log from '../shared/log.ts'
33
import util from '../shared/util.ts'
44
import type { RouterURL } from '../types.ts'
55
import type { Application } from './app.ts'
6-
import { createHtml, getAlephPkgUri } from './helper.ts'
6+
import { createHtml } from './helper.ts'
77

88
/** The framework render result of SSR. */
99
export type FrameworkRenderResult = {
@@ -29,13 +29,11 @@ export class Renderer {
2929

3030
constructor(app: Application) {
3131
this.#app = app
32-
this.#renderer = { render: async () => ({ head: [], body: '', scripts: [], data: null }) }
32+
this.#renderer = { render: async () => { throw new Error("framework renderer is undefined") } }
3333
}
3434

35-
async load() {
36-
const rendererModuleUrl = `${getAlephPkgUri()}/framework/${this.#app.config.framework}/renderer.ts`
37-
const { jsFile } = await this.#app.addModule(rendererModuleUrl, { once: true })
38-
this.#renderer = await import('file://' + jsFile)
35+
setFrameworkRenderer(renderer: FrameworkRenderer) {
36+
this.#renderer = renderer
3937
}
4038

4139
private getHTMLScripts() {

0 commit comments

Comments
 (0)