-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
Server
type for server entrypoint, unit test CSP functionality (#…
…981)
- Loading branch information
Showing
14 changed files
with
274 additions
and
525 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,42 @@ | ||
--- | ||
'sku': minor | ||
--- | ||
|
||
Export a `Server` type for `sku`'s server entrypoint | ||
|
||
**EXAMPLE USAGE**: | ||
|
||
```tsx | ||
// server.tsx | ||
import { renderToString } from 'react-dom/server'; | ||
import type { Server } from 'sku'; | ||
import { App } from './App'; | ||
|
||
export default (): Server => ({ | ||
renderCallback: ({ SkuProvider, getHeadTags, getBodyTags }, _req, res) => { | ||
const app = renderToString( | ||
<SkuProvider> | ||
<App /> | ||
</SkuProvider>, | ||
); | ||
|
||
res.send(/* html */ ` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>My Awesome Project</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
${getHeadTags()} | ||
</head> | ||
<body> | ||
<div id="app">${app}</div> | ||
${getBodyTags()} | ||
</body> | ||
</html>`); | ||
}, | ||
}); | ||
``` | ||
|
||
> [!NOTE] | ||
> The `Server` type may conflict with existing attempts in projects to define a `Server` type. |
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
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
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
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
Oops, something went wrong.