This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_lambda_function" "website_generator" { | |
# the path to the lambda source code | |
filename = "${var.app_package}" | |
function_name = "website_generator" | |
runtime = "nodejs6.10" | |
# references the role's arn using the resource's | |
# output variable | |
role = "${aws_iam_role.website_generator_role.arn}" | |
# name of the export function | |
handler = "handler.default" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import createWebpackConfig from './webpack.config' | |
const s3 = new AWS.S3() | |
// the lambda handler | |
// event contains information from the source of the lambda invocation | |
// it could be data provided by manually invoking it, a payload from | |
// API Gateway, an S3 putObject event or an SNS topic message. | |
// we are going to create a scheduled lambda function through CloudWatch | |
// and don't actually use the event data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react' | |
import { render } from 'react-dom' | |
import { rehydrate } from 'glamor' | |
export default function () { | |
const ssr = (window as SSRWindow).ssr | |
rehydrate(ssr.cssIds) | |
// use require to ensure glamor rehydrate is called |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react' | |
export default function Template({ css, js, body, ssr }) { | |
return ( | |
<html lang='en' data-timestamp={(new Date()).toISOString()}> | |
<head> | |
<title>{ssr.appProps.username}</title> | |
<style>{css}</style> | |
</head> | |
<body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// index.ts imports both the mount and ssr functions | |
// because it's the entry point for the server and | |
// the browser | |
import mount from './mount' | |
import ssr from './ssr' | |
// dont mount if we are not running in the browser context | |
if (typeof document !== 'undefined') mount() | |
// the exported ssr function is only called by |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
webpack-dev-server --env.FOO bar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function Template({ body, ssr, js }) { | |
return ( | |
<html> | |
<head> | |
<title>{ssr.appProps.username}</title> | |
</head> | |
<body> | |
<div id='react-root' dangerouslySetInnerHTML={{ __html: body }} /> | |
<script dangerouslySetInnerHTML={{ __html: `window.ssr = ${JSON.stringify(ssr)}` }} /> | |
{ js.map(src => <script src={src} />) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react' | |
import { renderToString, renderToStaticMarkup } from 'react-dom/server' | |
import Template from './components/Template' | |
import App from './components/App' | |
// our simple ssr function accepts appProps and a webpackStats | |
// object provided by static-website-generator-webpack-plugin | |
export default function ssr({ webpackStats, appProps }) { | |
// fetch a list of all the assets created by the webpack compiler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default async function getProps(username) { | |
const sumary = await getGithubSummary(username) | |
return summary | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import getProps from './getProps' | |
// webpack supports exporting a function in your config | |
// without needing any changes to start the dev server | |
export default async function createWebpackConfig() { | |
// fetch our latest app props | |
const appProps = await getProps({ | |
// variable set by dotenv for development | |
github: process.env.GITHUB_USERNAME | |
}) |