Do some SSR cleanups

This commit is contained in:
Amit Jakubowicz 2019-10-03 11:47:57 +02:00
parent ac89e6e9f5
commit 14b9198433
11 changed files with 89 additions and 55 deletions

3
@types/index.d.ts vendored
View file

@ -1,4 +1,5 @@
export type EventStatus = 'confirmed' | 'canceled'
export type EventStatus = "confirmed" | "canceled"
// tslint:disable
// graphql typescript definitions
declare namespace GQL {

View file

@ -16,6 +16,7 @@
"packages/*"
],
"dependencies": {
"@babel/node": "^7.6.2",
"@emotion/core": "^10.0.15",
"@emotion/styled": "^10.0.12",
"@types/mustache": "^0.8.32",
@ -64,6 +65,7 @@
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.3.3",
"@emotion/babel-preset-css-prop": "^10.0.9",
"@types/express": "^4.17.1",
"@types/jest": "^24.0.6",
"@types/node": "^11.9.4",
"@types/react": "^16.4.18",

View file

@ -13,6 +13,7 @@
],
"plugins": [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread"
"@babel/proposal-object-rest-spread",
"emotion"
]
}

View file

@ -15,45 +15,13 @@ import Footer from "./Footer"
import Header from "./Header/Header"
import OccurrenceDetails from "./Occurrence/OccurrenceDetails"
import firaSansLatin100 from "typeface-fira-sans/files/fira-sans-latin-100.woff"
import firaSansLatin600 from "typeface-fira-sans/files/fira-sans-latin-600.woff"
import firaSansLatin800 from "typeface-fira-sans/files/fira-sans-latin-800.woff"
const App = () => (
<Root>
<Global
styles={css`
@font-face {
font-family: "Fira Sans";
font-style: normal;
font-display: swap;
font-weight: 100;
src:
url(${firaSansLatin100}) format('woff'); /* Modern Browsers */
}
}
@font-face {
font-family: "Fira Sans";
font-style: normal;
font-display: swap;
font-weight: 600;
src:
url(${firaSansLatin600}) format('woff'); /* Modern Browsers */
}
}
@font-face {
font-family: "Fira Sans";
font-style: normal;
font-display: swap;
font-weight: 800;
src:
url(${firaSansLatin800}) format('woff'); /* Modern Browsers */
}
}
body {
margin: 0;
height: 100vh;
font-family: "Fira Sans";
}
#app {
height: 100%;

View file

@ -1,5 +1,5 @@
import * as addHours from "date-fns/add_hours"
import * as format from "date-fns/format"
import addHours from "date-fns/add_hours"
import format from "date-fns/format"
import {Field, Form, Formik} from "formik"
import { PrimaryButton } from "qpa-components"
import * as React from "react"

View file

@ -11,13 +11,10 @@ import fetch from "node-fetch"
import * as path from "path"
import * as React from "react"
import { getDataFromTree } from "react-apollo"
import * as ReactDOMServer from "react-dom/server"
import App from "../App/App"
import SSRProviders from "./SSRProviders"
export const httpSSRHandler = async (req: Request, res: Response) => {
res.status(200)
console.log("Cookie header", req.header("Cookie"))
const httpLink = new HttpLink({
uri: process.env.API_URL || "http://localhost:4000/graphql",
fetch,

View file

@ -1,4 +1,4 @@
import * as express from "express"
import express from "express"
import { httpSSRHandler } from "./handler"
const port = 5000

15
src/SSR/tsconfig.json Normal file
View file

@ -0,0 +1,15 @@
{
"compilerOptions": {
"skipLibCheck": true,
"sourceMap": true,
"esModuleInterop": true,
"jsx": "react",
"module": "es2015",
"moduleResolution": "node",
"lib": [
"dom",
"es7",
"esnext.asynciterable"
]
}
}

View file

@ -12,7 +12,7 @@
"esnext.asynciterable"
]
},
"include": ["src"],
"include": ["src", "@types/index.d.ts"],
"exclude": [
".*/__tests__/.*", "node_modules", "dist", "lib", "__tests__"
]

View file

@ -1,9 +1,6 @@
import * as express from "express"
import * as HtmlWebpackPlugin from "html-webpack-plugin"
import HtmlWebpackPlugin from "html-webpack-plugin"
import * as path from "path"
import * as webpack from "webpack"
import * as WebpackDevServer from "webpack-dev-server"
import {httpSSRHandler} from "./src/SSR/handler"
const config: webpack.Configuration = {
entry: "./src/App/index.tsx",
@ -13,20 +10,16 @@ const config: webpack.Configuration = {
devServer: {
historyApiFallback: true,
hot: true,
// before: (app: express.Application, server: WebpackDevServer) => {
// todo: improve the regex
// app.get(/^((?!\.\w+).)*$/, httpSSRHandler)
// },
proxy: {
"/graphql": {
redirect: false,
changeOrigin: true,
target: `http://localhost:4000`,
target: `https://alpha.quepasaalpujarra.com`,
},
"/api": {
redirect: false,
changeOrigin: true,
target: `http://localhost:4000`,
target: `https://alpha.quepasaalpujarra.com`,
},
},
@ -53,7 +46,6 @@ const config: webpack.Configuration = {
],
plugins: [
"@babel/plugin-proposal-class-properties",
// "module:@emotion/babel-preset-css-prop"
].filter(Boolean),
},
},

View file

@ -250,6 +250,19 @@
esutils "^2.0.2"
js-tokens "^4.0.0"
"@babel/node@^7.6.2":
version "7.6.2"
resolved "https://registry.yarnpkg.com/@babel/node/-/node-7.6.2.tgz#a94479f95ee2008342f4847346c8bb8ff2770f44"
integrity sha512-59UxvVtRpVpL5i0KTcw41FqLNPT/Jc9k/48Rq00wfN49lAIQeRKGwZ6xX1FWlCfcIGP+5l4rfZajORvmYkhfGg==
dependencies:
"@babel/register" "^7.6.2"
commander "^2.8.1"
core-js "^3.2.1"
lodash "^4.17.13"
node-environment-flags "^1.0.5"
regenerator-runtime "^0.13.3"
v8flags "^3.1.1"
"@babel/parser@^7.1.0", "@babel/parser@^7.4.3", "@babel/parser@^7.4.4", "@babel/parser@^7.5.5":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.5.5.tgz#02f077ac8817d3df4a832ef59de67565e71cca4b"
@ -731,6 +744,17 @@
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-transform-typescript" "^7.3.2"
"@babel/register@^7.6.2":
version "7.6.2"
resolved "https://registry.yarnpkg.com/@babel/register/-/register-7.6.2.tgz#25765a922202cb06f8bdac5a3b1e70cd6bf3dd45"
integrity sha512-xgZk2LRZvt6i2SAUWxc7ellk4+OYRgS3Zpsnr13nMS1Qo25w21Uu8o6vTOAqNaxiqrnv30KTYzh9YWY2k21CeQ==
dependencies:
find-cache-dir "^2.0.0"
lodash "^4.17.13"
mkdirp "^0.5.1"
pirates "^4.0.0"
source-map-support "^0.5.9"
"@babel/runtime@^7.1.2", "@babel/runtime@^7.4.0", "@babel/runtime@^7.4.2", "@babel/runtime@^7.4.3":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.5.5.tgz#74fba56d35efbeca444091c7850ccd494fd2f132"
@ -1143,6 +1167,15 @@
"@types/express-serve-static-core" "*"
"@types/serve-static" "*"
"@types/express@^4.17.1":
version "4.17.1"
resolved "https://registry.yarnpkg.com/@types/express/-/express-4.17.1.tgz#4cf7849ae3b47125a567dfee18bfca4254b88c5c"
integrity sha512-VfH/XCP0QbQk5B5puLqTLEeFgR8lfCJHZJKkInZ9mkYd+u8byX0kztXEQxEk4wZXJs8HI+7km2ALXjn4YKcX9w==
dependencies:
"@types/body-parser" "*"
"@types/express-serve-static-core" "*"
"@types/serve-static" "*"
"@types/glob@^7.1.1":
version "7.1.1"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575"
@ -2796,6 +2829,11 @@ core-js@^1.0.0:
resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636"
integrity sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY=
core-js@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.2.1.tgz#cd41f38534da6cc59f7db050fe67307de9868b09"
integrity sha512-Qa5XSVefSVPRxy2XfUC13WbvqkxhkwB3ve+pgCQveNgYzbM/UxZeu1dcOX/xr4UmfUd+muuvsaxilQzCyUurMw==
core-util-is@1.0.2, core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
@ -5903,6 +5941,14 @@ no-case@^2.2.0:
dependencies:
lower-case "^1.1.1"
node-environment-flags@^1.0.5:
version "1.0.6"
resolved "https://registry.yarnpkg.com/node-environment-flags/-/node-environment-flags-1.0.6.tgz#a30ac13621f6f7d674260a54dede048c3982c088"
integrity sha512-5Evy2epuL+6TM0lCQGpFIj6KwiEsGh1SrHUhTbNX+sLbBtjidPZFAnVK9y5yU1+h//RitLbRHTIMyxQPtxMdHw==
dependencies:
object.getownpropertydescriptors "^2.0.3"
semver "^5.7.0"
node-fetch@^1.0.1:
version "1.7.3"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
@ -6524,7 +6570,7 @@ pinkie@^2.0.0:
resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
integrity sha1-clVrgM+g1IqXToDnckjoDtT3+HA=
pirates@^4.0.1:
pirates@^4.0.0, pirates@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/pirates/-/pirates-4.0.1.tgz#643a92caf894566f91b2b986d2c66950a8e2fb87"
integrity sha512-WuNqLTbMI3tmfef2TKxlQmAiLHKtFhlsCZnPIpuv2Ow0RDVO8lfy1Opf4NUzlMXLjPl+Men7AuVdX6TA+s+uGA==
@ -6962,7 +7008,7 @@ regenerate@^1.4.0:
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11"
integrity sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg==
regenerator-runtime@^0.13.2:
regenerator-runtime@^0.13.2, regenerator-runtime@^0.13.3:
version "0.13.3"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz#7cf6a77d8f5c6f60eb73c5fc1955b2ceb01e6bf5"
integrity sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw==
@ -7289,6 +7335,11 @@ semver-diff@^2.0.0:
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.0.tgz#790a7cf6fea5459bac96110b29b60412dc8ff96b"
integrity sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==
semver@^5.7.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==
semver@^6.0.0, semver@^6.1.1:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
@ -7501,7 +7552,7 @@ source-map-resolve@^0.5.0:
source-map-url "^0.4.0"
urix "^0.1.0"
source-map-support@^0.5.6, source-map-support@~0.5.12:
source-map-support@^0.5.6, source-map-support@^0.5.9, source-map-support@~0.5.12:
version "0.5.13"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.13.tgz#31b24a9c2e73c2de85066c0feb7d44767ed52932"
integrity sha512-SHSKFHadjVA5oR4PPqhtAVdcBWwRYVd6g6cAXnIbRiIwc2EhPrTuKUBdSLvlEKyIP3GCf89fltvcZiP9MMFA1w==
@ -8396,6 +8447,13 @@ v8-compile-cache@2.0.3:
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.0.3.tgz#00f7494d2ae2b688cfe2899df6ed2c54bef91dbe"
integrity sha512-CNmdbwQMBjwr9Gsmohvm0pbL954tJrNzf6gWL3K+QMQf00PF7ERGrEiLgjuU3mKreLC2MeGhUsNV9ybTbLgd3w==
v8flags@^3.1.1:
version "3.1.3"
resolved "https://registry.yarnpkg.com/v8flags/-/v8flags-3.1.3.tgz#fc9dc23521ca20c5433f81cc4eb9b3033bb105d8"
integrity sha512-amh9CCg3ZxkzQ48Mhcb8iX7xpAfYJgePHxWMQCBWECpOSqJUXgY26ncA61UTV0BkPqfhcy6mzwCIoP4ygxpW8w==
dependencies:
homedir-polyfill "^1.0.1"
validate-npm-package-license@^3.0.1:
version "3.0.4"
resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz#fc91f6b9c7ba15c857f4cb2c5defeec39d4f410a"