├── tests ├── _fixtures │ ├── foo.js │ ├── empty-string.ts │ └── index.html ├── setup.ts ├── client │ └── sample-test.spec.ts ├── shared │ └── PrerenderData.spec.ts └── server │ └── server.spec.ts ├── .gitignore ├── src ├── client │ ├── resources │ │ ├── favicon.ico │ │ └── images │ │ │ ├── sample-image-1.png │ │ │ └── sample-image-2.png │ ├── pages │ │ ├── HomePage.tsx │ │ ├── SamplePage2.tsx │ │ └── SamplePage1.tsx │ ├── index.html │ ├── Index.tsx │ ├── serverData.ts │ └── App.tsx ├── shared │ ├── models.ts │ ├── types.d.ts │ └── PrerenderedData.ts └── server │ ├── app.ts │ ├── configuration.ts │ ├── middleware │ ├── reactMiddleware.tsx │ ├── errorMiddleware.ts │ └── routing.ts │ ├── server.ts │ └── ssr │ └── renderReactAsync.tsx ├── tsconfig.json ├── jest.config.ts ├── readme.md ├── package.json └── webpack.config.ts /tests/_fixtures/foo.js: -------------------------------------------------------------------------------- 1 | console.log('foo'); -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .vscode/ 3 | dist/ -------------------------------------------------------------------------------- /tests/_fixtures/empty-string.ts: -------------------------------------------------------------------------------- 1 | export default ""; -------------------------------------------------------------------------------- /src/client/resources/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marceloaugusto80/react-ssr-express/HEAD/src/client/resources/favicon.ico -------------------------------------------------------------------------------- /src/shared/models.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Just an example model. 3 | */ 4 | export interface ExampleModel { 5 | message: string; 6 | id: number 7 | } 8 | -------------------------------------------------------------------------------- /src/client/resources/images/sample-image-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marceloaugusto80/react-ssr-express/HEAD/src/client/resources/images/sample-image-1.png -------------------------------------------------------------------------------- /src/client/resources/images/sample-image-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marceloaugusto80/react-ssr-express/HEAD/src/client/resources/images/sample-image-2.png -------------------------------------------------------------------------------- /src/server/app.ts: -------------------------------------------------------------------------------- 1 | import { createServer } from "server/server"; 2 | import { PORT } from "server/configuration"; 3 | 4 | const server = createServer(); 5 | 6 | server.listen(PORT, () => { 7 | console.log(`Server listening to port ${PORT}`); 8 | }); -------------------------------------------------------------------------------- /tests/setup.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | 3 | // here we are mocking the environment variables used by the server 4 | process.env.PUBLIC_DIR_PATH = path.join(__dirname, "_fixtures"); 5 | process.env.HTML_TEMPLATE_PATH = path.join(__dirname, "_fixtures/index.html"); -------------------------------------------------------------------------------- /tests/client/sample-test.spec.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @jest-environment jsdom 3 | */ 4 | 5 | // put your imports here, after jest-environemnt pragma 6 | 7 | describe("Sample", () => { 8 | 9 | test("sample test", () => { 10 | 11 | expect(window).toBeDefined(); 12 | 13 | }); 14 | 15 | }); 16 | 17 | -------------------------------------------------------------------------------- /src/client/pages/HomePage.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | /** 4 | * The home page. Nothing fancy here. 5 | * 6 | * @returns react component. 7 | */ 8 | export default function HomePage() { 9 | return ( 10 |
The home page.
13 |The images below were fetched from the server.
14 |{model.message}
19 | } 20 | { 21 | !model && 22 |If you're seeing this, means that you navigated to this page by the BrowserRouter.
24 |If you're running the application server, refresh the page to receive a ssr version of it.
25 |