homepage-frontend/src/router.js

36 lines
836 B
JavaScript
Raw Normal View History

2017-07-23 15:24:59 +00:00
//@flow
2017-07-28 21:03:26 +00:00
import express, { Router } from "express"
2017-07-29 11:15:23 +00:00
import type { $Request, $Response } from "express"
2017-07-28 21:03:26 +00:00
import Inferno from "inferno"
2017-07-29 08:34:15 +00:00
import InfernoServer from "inferno-server"
import { ServerStyleSheet } from "styled-components"
2017-07-28 21:03:26 +00:00
import App from "./app"
2017-07-23 15:24:59 +00:00
import path from "path"
2017-07-28 21:03:26 +00:00
import ejs from "ejs"
import indexFile from "raw-loader!./index.ejs"
2017-07-23 15:24:59 +00:00
const router = new Router
2017-07-28 21:03:26 +00:00
const sheet = new ServerStyleSheet()
const template = ejs.compile(indexFile)
const content = InfernoServer.renderToStaticMarkup(sheet.collectStyles(<App />))
const title = "Arwed Mett"
const style = sheet.getStyleTags()
const indexPage = template({
content,
title,
style
2017-07-23 15:24:59 +00:00
})
2017-07-29 11:15:23 +00:00
router.get("/", (req: $Request, res: $Response) => {
2017-07-28 21:03:26 +00:00
res.send(indexPage)
2017-07-23 15:24:59 +00:00
})
2017-08-02 20:54:02 +00:00
router.use(express.static(path.join(__dirname, "static"), {
maxAge: 900000000
}))
2017-07-28 21:03:26 +00:00
2017-07-23 15:24:59 +00:00
export default router