extract sendJsx function

This commit is contained in:
MapleLeaf
2022-01-03 01:56:45 -06:00
committed by Darius
parent 511dec3864
commit 70ec77d684
2 changed files with 8 additions and 7 deletions

View 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)}`)
}

View File

@@ -1,10 +1,9 @@
import compression from "compression"
import type { Response } from "express"
import express from "express"
import httpTerminator from "http-terminator"
import pino from "pino"
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 { serveTailwindCss } from "./helpers/tailwind"
import { Landing } from "./pages/landing"
@@ -12,11 +11,6 @@ import { Landing } from "./pages/landing"
const logger = pino()
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()
.use(compression())
.get("/tailwind.css", serveTailwindCss())