Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
@kdujs/server-renderer-canary
Advanced tools
renderToString
Signature
function renderToString(
input: App | KNode,
context?: SSRContext
): Promise<string>
Usage
const { createSSRApp } = require('kdu')
const { renderToString } = require('@kdujs/server-renderer')
const app = createSSRApp({
data: () => ({ msg: 'hello' }),
template: `<div>{{ msg }}</div>`
})
;(async () => {
const html = await renderToString(app)
console.log(html)
})()
If the rendered app contains teleports, the teleported content will not be part of the rendered string. Instead, they are exposed under the teleports
property of the ssr context object:
const ctx = {}
const html = await renderToString(app, ctx)
console.log(ctx.teleports) // { '#teleported': 'teleported content' }
renderToNodeStream
Renders input as a Node.js Readable stream.
Signature
function renderToNodeStream(input: App | KNode, context?: SSRContext): Readable
Usage
// inside a Node.js http handler
renderToNodeStream(app).pipe(res)
Note: This method is not supported in the ESM build of @kdujs/server-renderer
, which is decoupled from Node.js environments. Use pipeToNodeWritable
instead.
pipeToNodeWritable
Render and pipe to an existing Node.js Writable stream instance.
Signature
function pipeToNodeWritable(
input: App | KNode,
context: SSRContext = {},
writable: Writable
): void
Usage
// inside a Node.js http handler
pipeToNodeWritable(app, {}, res)
renderToWebStream
Renders input as a Web ReadableStream.
Signature
function renderToWebStream(
input: App | KNode,
context?: SSRContext
): ReadableStream
Usage
// inside an environment with ReadableStream support
return new Response(renderToWebStream(app))
Note: in environments that do not expose ReadableStream
constructor in the global scope, pipeToWebWritable
should be used instead.
pipeToWebWritable
Render and pipe to an existing Web WritableStream instance.
Signature
function pipeToWebWritable(
input: App | KNode,
context: SSRContext = {},
writable: WritableStream
): void
Usage
This is typically used in combination with TransformStream
:
// TransformStream is available in environments such as CloudFlare workers.
// in Node.js, TransformStream needs to be explicitly imported from 'stream/web'
const { readable, writable } = new TransformStream()
pipeToWebWritable(app, {}, writable)
return new Response(readable)
renderToSimpleStream
Renders input in streaming mode using a simple readable interface.
Signature
function renderToSimpleStream(
input: App | KNode,
context: SSRContext,
options: SimpleReadable
): SimpleReadable
interface SimpleReadable {
push(content: string | null): void
destroy(err: any): void
}
Usage
let res = ''
renderToSimpleStream(
app,
{},
{
push(chunk) {
if (chunk === null) {
// done
console(`render complete: ${res}`)
} else {
res += chunk
}
},
destroy(err) {
// error encountered
}
}
)
FAQs
@kdujs/server-renderer
The npm package @kdujs/server-renderer-canary receives a total of 295 weekly downloads. As such, @kdujs/server-renderer-canary popularity was classified as not popular.
We found that @kdujs/server-renderer-canary demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.