extract sendJsx function
This commit is contained in:
7
packages/docs-new/src/helpers/send-jsx.ts
Normal file
7
packages/docs-new/src/helpers/send-jsx.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import type { Response } from "express"
|
||||||
|
import { renderToStaticMarkup } from "react-dom/server.js"
|
||||||
|
|
||||||
|
export function sendJsx(res: Response, jsx: React.ReactElement) {
|
||||||
|
res.set("Content-Type", "text/html")
|
||||||
|
res.send(`<!DOCTYPE html>\n${renderToStaticMarkup(jsx)}`)
|
||||||
|
}
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
import compression from "compression"
|
import compression from "compression"
|
||||||
import type { Response } from "express"
|
|
||||||
import express from "express"
|
import express from "express"
|
||||||
import httpTerminator from "http-terminator"
|
import httpTerminator from "http-terminator"
|
||||||
import pino from "pino"
|
import pino from "pino"
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import { renderToStaticMarkup } from "react-dom/server.js"
|
import { sendJsx } from "./helpers/send-jsx"
|
||||||
import { serveFile } from "./helpers/serve-file"
|
import { serveFile } from "./helpers/serve-file"
|
||||||
import { serveTailwindCss } from "./helpers/tailwind"
|
import { serveTailwindCss } from "./helpers/tailwind"
|
||||||
import { Landing } from "./pages/landing"
|
import { Landing } from "./pages/landing"
|
||||||
@@ -12,11 +11,6 @@ import { Landing } from "./pages/landing"
|
|||||||
const logger = pino()
|
const logger = pino()
|
||||||
const port = process.env.PORT || 3000
|
const port = process.env.PORT || 3000
|
||||||
|
|
||||||
function sendJsx(res: Response, jsx: React.ReactElement) {
|
|
||||||
res.set("Content-Type", "text/html")
|
|
||||||
res.send(`<!DOCTYPE html>\n${renderToStaticMarkup(jsx)}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
.use(compression())
|
.use(compression())
|
||||||
.get("/tailwind.css", serveTailwindCss())
|
.get("/tailwind.css", serveTailwindCss())
|
||||||
|
|||||||
Reference in New Issue
Block a user