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.
- package/README.md +19 -25
- 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
|
|
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 (
|
|
25
|
+
### Server Entry (Express with React Router)
|
|
26
26
|
|
|
27
27
|
```typescript
|
|
28
|
-
import
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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`)
|