|
1 | 1 | import { ServerResponse } from 'http'; |
2 | | -import { createFactory } from 'react'; |
| 2 | +import React from 'react'; |
3 | 3 | import { renderToNodeStream } from 'react-dom/server'; |
4 | 4 |
|
5 | | -import IndexPage from '../pages/index'; |
6 | | -import ResultPage from '../pages/result'; |
7 | | -import ComparePage from '../pages/compare'; |
8 | | -import NotFoundPage from '../pages/404'; |
9 | | -import ServerErrorPage from '../pages/500'; |
10 | | -import ParseFailurePage from '../pages/parse-failure'; |
11 | | - |
12 | | -const IndexFactory = createFactory(IndexPage); |
13 | | -const ResultFactory = createFactory(ResultPage); |
14 | | -const CompareFactory = createFactory(ComparePage); |
15 | | -const NotFoundFactory = createFactory(NotFoundPage); |
16 | | -const ServerErrorFactory = createFactory(ServerErrorPage); |
17 | | -const ParseFailureFactory = createFactory(ParseFailurePage); |
| 5 | +import Index from './index'; |
| 6 | +import Result from './result'; |
| 7 | +import Compare from './compare'; |
| 8 | +import NotFound from './404'; |
| 9 | +import ServerError from './500'; |
| 10 | +import ParseFailure from './parse-failure'; |
18 | 11 |
|
19 | 12 | import { getResultProps } from '../page-props/results'; |
20 | 13 | import { getCompareProps } from '../page-props/compare'; |
@@ -161,19 +154,21 @@ async function routePage(pathname: string, query: ParsedUrlQuery, tmpDir: string |
161 | 154 | try { |
162 | 155 | switch (pathname) { |
163 | 156 | case pages.index: |
164 | | - return IndexFactory(); |
| 157 | + return <Index />; |
165 | 158 | case pages.parseFailure: |
166 | | - return ParseFailureFactory(); |
| 159 | + return <ParseFailure />; |
167 | 160 | case pages.result: |
168 | | - return (query.p || '').includes(',') |
169 | | - ? CompareFactory(await getCompareProps(query, tmpDir)) |
170 | | - : ResultFactory(await getResultProps(query, tmpDir)); |
| 161 | + return (query.p || '').includes(',') ? ( |
| 162 | + <Compare {...await getCompareProps(query, tmpDir)} /> |
| 163 | + ) : ( |
| 164 | + <Result {...await getResultProps(query, tmpDir)} /> |
| 165 | + ); |
171 | 166 | default: |
172 | | - return NotFoundFactory(); |
| 167 | + return <NotFound />; |
173 | 168 | } |
174 | 169 | } catch (e) { |
175 | 170 | console.error(`ERROR: ${e.message}`); |
176 | | - return ServerErrorFactory(); |
| 171 | + return <ServerError />; |
177 | 172 | } |
178 | 173 | } |
179 | 174 |
|
|
0 commit comments