organize stuff

This commit is contained in:
MapleLeaf
2021-12-31 13:35:27 -06:00
committed by Darius
parent 6e18aac5bd
commit dcace52ac9
6 changed files with 6 additions and 17 deletions

View File

@@ -2,8 +2,8 @@ import { description } from "reacord/package.json"
import { Meta, Title } from "react-head"
import { Route, Routes } from "react-router"
import { Link } from "react-router-dom"
import { DocumentPage } from "./document-page"
import { LandingPage } from "./landing-page"
import { DocumentPage } from "./pages/document-page"
import { LandingPage } from "./pages/landing-page"
export function App() {
return (

View File

@@ -1,11 +0,0 @@
import * as React from "react"
export function Counter() {
const [count, setCount] = React.useState(0)
return (
<div>
<p>You clicked {count} times!</p>
<button onClick={() => setCount(count + 1)}>Click me</button>
</div>
)
}

View File

@@ -1,65 +0,0 @@
import compression from "compression"
import express, { Router } from "express"
import { resolve } from "node:path"
import { createServer as createViteServer } from "vite"
import type * as entryModule from "./entry.server"
async function createDevelopmentRouter() {
const vite = await createViteServer({
server: { middlewareMode: "ssr" },
})
return Router()
.use(vite.middlewares)
.use("*", async (req, res) => {
const url = req.originalUrl
try {
const { render } = (await vite.ssrLoadModule(
"/src/entry.server.tsx",
)) as typeof entryModule
const html = await vite.transformIndexHtml(url, await render(url))
res.status(200).set({ "Content-Type": "text/html" }).end(html)
} catch (error: any) {
vite.ssrFixStacktrace(error)
console.error(error)
res.status(500).end(error.stack || error.message)
}
})
}
function createProductionRouter() {
return Router()
.use(compression())
.use(express.static(resolve("dist/client")))
.use("*", async (req, res) => {
try {
const { render }: typeof entryModule = await import(
"../dist/server/entry.server"
)
res
.status(200)
.set({ "Content-Type": "text/html" })
.end(await render(req.originalUrl))
} catch (error: any) {
console.error(error)
res.status(500).end(error.stack || error.message)
}
})
}
const app = express()
if (process.env.NODE_ENV === "production") {
app.use(createProductionRouter())
} else {
app.use(await createDevelopmentRouter())
}
const port = process.env.PORT || 3000
app.listen(port, () => {
console.log(`listening on http://localhost:${port}`)
})