-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
27 lines (21 loc) · 700 Bytes
/
index.ts
File metadata and controls
27 lines (21 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import express, { Request } from 'express'
import routes, { PageProps } from 'routes';
import renderHtml from './renderer';
const app = express()
app.use('/public', express.static('dist/public'));
Object.keys(routes).forEach(key => {
const route = routes[key] as PageProps
app.get(route.path, async (req, res) => {
const pageData = await route.getServerSideProps(req)
const pageHtml = await renderHtml({ url: req.url, pageData })
res.send(pageHtml)
})
app.get(`/api${route.path}`, async (req, res) => {
const pageData = await route.getServerSideProps(req)
res.json(pageData)
})
})
app.get('/*', async (req, res) => {
res.send("Page NotFound")
})
app.listen(3000)