fake-current-time 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +19 -25
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -18,41 +18,35 @@ npm install fake-current-time
18
18
 
19
19
  This example shows integration with React Router framework mode. The key concept is:
20
20
 
21
- - **Server**: Parse offset from cookie and wrap rendering with `runner.run(offset, ...)`
21
+ - **Server**: Parse offset from cookie and wrap request handling with `runner.run(offset, ...)`
22
22
  - **Client**: Call `setup()` to initialize time manipulation
23
23
  - **UI**: Use `setOffset()` and `clearOffset()` to control time via cookie
24
24
 
25
- ### Server Entry (`entry.server.tsx`)
25
+ ### Server Entry (Express with React Router)
26
26
 
27
27
  ```typescript
28
- import type { AppLoadContext, EntryContext } from "react-router";
28
+ import express from "express";
29
+ import { createRequestHandler } from "@react-router/express";
29
30
  import { setup, parseOffsetFromCookie } from "fake-current-time/node";
30
31
 
32
+ const app = express();
33
+
31
34
  // Do NOT setup in production
32
35
  const runner = process.env.STAGE !== "production" ? setup() : null;
33
36
 
34
- export default function handleRequest(
35
- request: Request,
36
- responseStatusCode: number,
37
- responseHeaders: Headers,
38
- routerContext: EntryContext,
39
- loadContext: AppLoadContext,
40
- ) {
41
- const offset = runner
42
- ? parseOffsetFromCookie(request.headers.get("Cookie") || "")
43
- : undefined;
44
-
45
- const render = () => {
46
- return new Promise((resolve, reject) => {
47
- // ...
48
- const { pipe, abort } = renderToPipeableStream(/* ... */, {
49
- // ...
50
- });
51
- });
52
- };
53
-
54
- return offset && runner ? runner.run(offset, render) : render();
55
- }
37
+ app.all(
38
+ "*",
39
+ (req, _, next) => {
40
+ const offset = runner
41
+ ? parseOffsetFromCookie(req.headers.cookie || "")
42
+ : undefined;
43
+
44
+ return offset && runner ? runner.run(offset, next) : next();
45
+ },
46
+ createRequestHandler({
47
+ // ...
48
+ }),
49
+ );
56
50
  ```
57
51
 
58
52
  ### Client Entry (`entry.client.tsx`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fake-current-time",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Manipulate current time in your application for development and staging environments",
5
5
  "keywords": [
6
6
  "time",