Skip to content

Commit 9de2710

Browse files
author
Andre Rabold
committed
Configure for TypeScript use
1 parent 0d6398b commit 9de2710

22 files changed

+573
-56
lines changed

.babelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
}
99
}
1010
],
11+
"@babel/preset-typescript",
1112
"@babel/preset-react"
1213
],
1314
"plugins": [],

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ Lightweight boilerplate project to setup a React 16 web application on AWS Lambd
1010
- Universal app; server-side rendering with dynamic configuration context passed from backend to browser.
1111
- Self-contained; no additional setup steps necessary other than running `npx sls deploy`.
1212
- Lightweight; no mandatory `redux`, `react-router`, `sass`, `less` or any other 3rd party dependency for full flexibility.
13-
- Full ES6/7/8/9/10 with latest JavaScript features supported using Babel 7 and Webpack 4.
13+
- Full [TypeScript](https://www.typescriptlang.org/) support using Babel 7 and Webpack 4.
1414
- Working [Jest](https://jestjs.io/) test environment.
1515

16-
[Looking for the TypeScript version of this boilerplate?](https://github.com/arabold/serverless-react-boilerplate/tree/typescript)
16+
[Looking for the plain JavaScript version of this boilerplate?](https://github.com/arabold/serverless-react-boilerplate/)
1717

1818
## Overview
1919

2020
### How Does It Work?
2121

22-
The idea is that we use AWS Lambda to serve the dynamic part of our app, the server-side logic, and perform the server-side rendering. For all static data like images, stylesheets and even the app's `index.jsx` that is loaded in the browser, we use an S3 bucket for public hosting.
22+
The idea is that we use AWS Lambda to serve the dynamic part of our app, the server-side logic, and perform the server-side rendering. For all static data like images, stylesheets and even the app's `index.tsx` that is loaded in the browser, we use an S3 bucket for public hosting.
2323

2424
This combination makes our app fast and incredibly scalable. AWS will spin up new Lambda instances once your number of users increases, handling even the largest spikes fully automatically, while incurring virtually no costs when your app isn't used. At the same time S3 provides a robust and fast platform for your static content so you don't have to waste your own computing resources.
2525

@@ -61,8 +61,8 @@ The project is based on the [Serverless Framework](https://serverless.com) and m
6161

6262
Though we use the same source code for both the server-side and client-side rendering, the project will be packaged into two distinct bundles:
6363

64-
1. Backend code running on AWS Lambda. The main entry point is `./src/server/index.jsx`. The packaging is controlled by `webpack.server.config.js` and optimized for Node.js 12.
65-
2. Frontend code hosted in an S3 bucket and loaded by the browser. Main entry point is `./src/browser/index.jsx`. It's packaged using the `webpack.browser.config.js`, optimized for web browsers. The output files will have their content hash added to their names to enable long term caching in the browser.
64+
1. Backend code running on AWS Lambda. The main entry point is `./src/server/index.tsx`. The packaging is controlled by `webpack.server.config.js` and optimized for Node.js 12.
65+
2. Frontend code hosted in an S3 bucket and loaded by the browser. Main entry point is `./src/browser/index.tsx`. It's packaged using the `webpack.browser.config.js`, optimized for web browsers. The output files will have their content hash added to their names to enable long term caching in the browser.
6666

6767
## Customization
6868

@@ -72,7 +72,7 @@ Update the `serverless.yaml` with your project name and additional resources you
7272

7373
### Configuration
7474

75-
The frontend as well as the server-side code running on AWS Lambda share a common application configuration. Currently it is used for injecting the application name from the `public/manifest.json` as well as setting the public host names. You can extend the configuration by adding your own variables to `src/server/config.jsx`. They will become available in both your backend and frontend code via the `useConfig` hook:
75+
The frontend as well as the server-side code running on AWS Lambda share a common application configuration. Currently it is used for injecting the application name from the `public/manifest.json` as well as setting the public host names. You can extend the configuration by adding your own variables to `src/server/config.tsx`. They will become available in both your backend and frontend code via the `useConfig` hook:
7676

7777
```js
7878
import useConfig from "../components/useConfig";

handler.js renamed to handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import "source-map-support/register";
22
import render from "./src/server/render";
3+
import { Context, APIGatewayEvent, APIGatewayProxyResultV2 } from "aws-lambda";
34

4-
export const serve = async (event, context) => {
5+
export const serve = async (event: APIGatewayEvent, context: Context): Promise<APIGatewayProxyResultV2> => {
56
return {
67
statusCode: 200,
78
headers: {

0 commit comments

Comments
 (0)