Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert custom-server-hapi Example to Typescript (#34507)
In the contributing doc, it mentions "Examples should be TypeScript first, if possible" so I thought about converting some examples to be typescript along with updating a couple in my free time. Let me know if that would be an issue. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [X] Make sure the linting passes by running `yarn lint`
- Loading branch information
1 parent
9e77ef4
commit 670eb03
Showing
11 changed files
with
76 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"watch": ["server"], | ||
"exec": "ts-node --project tsconfig.server.json server/server.ts", | ||
"ext": "js ts" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
{ | ||
"private": true, | ||
"scripts": { | ||
"dev": "node server.js", | ||
"build": "next build", | ||
"start": "cross-env NODE_ENV=production node server.js" | ||
"dev": "nodemon", | ||
"build": "next build && tsc --project tsconfig.server.json", | ||
"start": "cross-env NODE_ENV=production node dist/server.js" | ||
}, | ||
"dependencies": { | ||
"@hapi/hapi": "^18.3.1", | ||
"cross-env": "^5.2.0", | ||
"@hapi/hapi": "^20.2.1", | ||
"cross-env": "^7.0.3", | ||
"next": "latest", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2" | ||
}, | ||
"devDependencies": { | ||
"@types/hapi__hapi": "^20.0.10", | ||
"@types/node": "^16.11.25", | ||
"@types/react": "^17.0.39", | ||
"@types/react-dom": "^17.0.11", | ||
"nodemon": "^2.0.15", | ||
"ts-node": "^10.5.0", | ||
"typescript": "^4.5.5" | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { NextServer } from 'next/dist/server/next' | ||
import type { Lifecycle } from '@hapi/hapi' | ||
import type { NextUrlWithParsedQuery } from 'next/dist/server/request-meta' | ||
|
||
const nextHandlerWrapper = (app: NextServer): Lifecycle.Method => { | ||
const handler = app.getRequestHandler() | ||
|
||
return async ({ raw, url, query }, h) => { | ||
const nextUrl = url as unknown as NextUrlWithParsedQuery | ||
nextUrl.query = query | ||
await handler(raw.req, raw.res, nextUrl) | ||
return h.close | ||
} | ||
} | ||
|
||
export { nextHandlerWrapper } |
6 changes: 3 additions & 3 deletions
6
examples/custom-server-hapi/server.js → examples/custom-server-hapi/server/server.ts
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"baseUrl": ".", | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": false, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"incremental": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve" | ||
}, | ||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], | ||
"exclude": ["node_modules"] | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"outDir": "dist", | ||
"lib": ["es2019"], | ||
"target": "es2019", | ||
"isolatedModules": false, | ||
"noEmit": false | ||
}, | ||
"include": ["server/**/*.ts"] | ||
} |
670eb03
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stats from current release
Default Build (Increase detected⚠️ )
General Overall increase⚠️
Page Load Tests Overall increase ✓
Client Bundles (main, webpack, commons) Overall decrease ✓
Legacy Client Bundles (polyfills)
Client Pages
Client Build Manifests
Rendered Page Sizes Overall increase⚠️
Diffs
Diff for main-HASH.js
Diff for index.html
Diff for link.html
Diff for withRouter.html
Default Build with SWC (Increase detected⚠️ )
General Overall increase⚠️
Page Load Tests Overall increase ✓
Client Bundles (main, webpack, commons) Overall decrease ✓
Legacy Client Bundles (polyfills)
Client Pages
Client Build Manifests
Rendered Page Sizes Overall decrease ✓
Diffs
Diff for main-HASH.js
Diff for index.html
Diff for link.html
Diff for withRouter.html