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

Commit f0b3b2b

Browse files
committed
Clean up
1 parent 99fe1ca commit f0b3b2b

File tree

5 files changed

+35
-36
lines changed

5 files changed

+35
-36
lines changed

framework/react/renderer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { createPageProps } from './pageprops.ts'
1212

1313
export type RendererStorage = {
1414
headElements: Map<string, { type: string, props: Record<string, any> }>
15-
scriptElements: Map<string, { props: Record<string, any> }>
15+
scripts: Map<string, { props: Record<string, any> }>
1616
}
1717

1818
export async function render(
@@ -29,7 +29,7 @@ export async function render(
2929
}
3030
const rendererStorage: RendererStorage = {
3131
headElements: new Map(),
32-
scriptElements: new Map(),
32+
scripts: new Map(),
3333
}
3434
const pagedataUrl = 'pagedata://' + url.pathname
3535
const asyncCalls: Array<Promise<any>> = []
@@ -124,7 +124,7 @@ export async function render(
124124
})
125125

126126
// get script tags
127-
rendererStorage.scriptElements.forEach(({ props }) => {
127+
rendererStorage.scripts.forEach(({ props }) => {
128128
const { children, dangerouslySetInnerHTML, ...attrs } = props
129129
if (dangerouslySetInnerHTML && util.isNEString(dangerouslySetInnerHTML.__html)) {
130130
ret.scripts.push({ ...attrs, innerText: dangerouslySetInnerHTML.__html })

framework/react/script.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import util from '../../shared/util.ts'
77
import { SSRContext } from './context.ts'
88

99
export default function Script(props: PropsWithChildren<ScriptHTMLAttributes<{}>>) {
10-
const { scriptElements } = useContext(SSRContext)
10+
const { scripts } = useContext(SSRContext)
1111

1212
if (util.inDeno) {
13-
const key = 'script-' + (scriptElements.size + 1)
14-
scriptElements.set(key, { props })
13+
const key = 'script-' + (scripts.size + 1)
14+
scripts.set(key, { props })
1515
}
1616

1717
// todo: insert page scripts in browser

import_map.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
22
"imports": {
33
"std/": "https://deno.land/[email protected]/",
4-
"brotli": "https://deno.land/x/[email protected]/mod.ts",
5-
"gzip": "https://deno.land/x/[email protected]/mod.ts",
64
"aleph/": "https://deno.land/x/[email protected]/",
75
"framework": "https://deno.land/x/[email protected]/framework/core/mod.ts",
86
"framework/react": "https://deno.land/x/[email protected]/framework/react/mod.ts",

server/api.ts

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -140,35 +140,38 @@ export class Request implements APIRequest {
140140
contentType = this.#resp.headers.get('Content-Type')!
141141
} else if (typeof data === 'string' && data.length > 0) {
142142
contentType = 'text/plain; charset=utf-8'
143+
this.#resp.headers.set('Content-Type', contentType)
143144
}
144-
let shouldCompress = false
145-
if (contentType) {
146-
if (contentType.startsWith('text/')) {
147-
shouldCompress = true
148-
} else if (/^application\/(javascript|typecript|wasm|json|xml)/i.test(contentType)) {
149-
shouldCompress = true
150-
} else if (/^image\/svg\+xml/i.test(contentType)) {
151-
shouldCompress = true
152-
}
153-
}
154-
if (shouldCompress && Deno.env.get('ALEPH_BUILD_MODE') !== 'development' && body.length > 1024) {
155-
const ae = this.headers.get('accept-encoding') || ''
156-
if (ae.includes('br')) {
157-
this.#resp.headers.set('Vary', 'Origin')
158-
this.#resp.headers.set('Content-Encoding', 'br')
159-
if (brotli === null) {
160-
const { compress } = await import('https://deno.land/x/[email protected]/mod.ts')
161-
brotli = compress
145+
if (Deno.env.get('ALEPH_BUILD_MODE') !== 'development') {
146+
let shouldCompress = false
147+
if (contentType) {
148+
if (contentType.startsWith('text/')) {
149+
shouldCompress = true
150+
} else if (/^application\/(javascript|typecript|wasm|json|xml)/i.test(contentType)) {
151+
shouldCompress = true
152+
} else if (/^image\/svg\+xml/i.test(contentType)) {
153+
shouldCompress = true
162154
}
163-
body = brotli(body)
164-
} else if (ae.includes('gzip')) {
165-
this.#resp.headers.set('Vary', 'Origin')
166-
this.#resp.headers.set('Content-Encoding', 'gzip')
167-
if (gzip === null) {
168-
const { gzipEncode } = await import('https://deno.land/x/[email protected]/mod.ts')
169-
gzip = gzipEncode
155+
}
156+
if (shouldCompress && body.length > 1024) {
157+
const ae = this.headers.get('accept-encoding') || ''
158+
if (ae.includes('br')) {
159+
this.#resp.headers.set('Vary', 'Origin')
160+
this.#resp.headers.set('Content-Encoding', 'br')
161+
if (brotli === null) {
162+
const { compress } = await import('https://deno.land/x/[email protected]/mod.ts')
163+
brotli = compress
164+
}
165+
body = brotli(body)
166+
} else if (ae.includes('gzip')) {
167+
this.#resp.headers.set('Vary', 'Origin')
168+
this.#resp.headers.set('Content-Encoding', 'gzip')
169+
if (gzip === null) {
170+
const denoflate = await import('https://deno.land/x/[email protected]/mod.ts')
171+
gzip = (data: Uint8Array) => denoflate.gzip(data, undefined)
172+
}
173+
body = gzip(body)
170174
}
171-
body = gzip(body)
172175
}
173176
}
174177
this.#resp.headers.set('Date', (new Date).toUTCString())

server/config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ export async function loadConfig(workingDir: string): Promise<Config> {
124124
return config
125125
}
126126

127-
128-
129127
/** load import maps from `import_map.json` */
130128
export async function loadImportMap(workingDir: string): Promise<ImportMap> {
131129
const importMap: ImportMap = { imports: {}, scopes: {} }

0 commit comments

Comments
 (0)