-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathReqRes.njs
More file actions
80 lines (64 loc) · 2.42 KB
/
ReqRes.njs
File metadata and controls
80 lines (64 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import Nullstack from 'nullstack'
class ReqRes extends Nullstack {
static async innerNestedServerFunctionFromClient(context) {
return context.request.originalUrl
}
static async nestedServerFunctionFromClient() {
return this.innerNestedServerFunctionFromClient()
}
static async serverFunctionFromClient(context) {
return context.request.originalUrl
}
static async innerNestedServerFunction(context) {
return context.request.originalUrl
}
static async serverFunction(context) {
return context.request.originalUrl
}
static async nestedServerFunction() {
return this.innerNestedServerFunction()
}
static async innerNestedExposedServerFunction(context) {
return context.request.originalUrl
}
static async nestedExposedServerFunction() {
return this.innerNestedExposedServerFunction()
}
static async exposedServerFunction(context) {
return context.request.originalUrl
}
async initiate() {
this.serverFunctionUrl = await ReqRes.serverFunction()
this.nestedServerFunctionUrl = await ReqRes.nestedServerFunction()
}
async fetchServerFunction({ slug }) {
const response = await fetch(`/${slug}.json`)
return response.json()
}
async hydrate() {
this.serverFunctionFromClientUrl = await ReqRes.serverFunctionFromClient()
this.nestedServerFunctionFromClientUrl = await ReqRes.nestedServerFunctionFromClient()
this.exposedServerFunctionUrl = await this.fetchServerFunction({ slug: 'exposed-server-function-url' })
this.nestedExposedServerFunctionUrl = await this.fetchServerFunction({ slug: 'nested-exposed-server-function-url' })
}
render() {
return (
<div
data-server-function={this.serverFunctionUrl === '/reqres'}
data-nested-server-function={this.nestedServerFunctionUrl === '/reqres'}
data-server-function-from-client={this.serverFunctionFromClientUrl?.endsWith?.(
'/serverFunctionFromClient.json',
)}
data-nested-server-function-from-client={this.nestedServerFunctionFromClientUrl?.endsWith?.(
'/nestedServerFunctionFromClient.json',
)}
data-exposed-server-function={this.exposedServerFunctionUrl === '/exposed-server-function-url.json'}
data-exposed-nested-server-function={
this.nestedExposedServerFunctionUrl === '/nested-exposed-server-function-url.json'
}
data-hydrated={this.hydrated}
/>
)
}
}
export default ReqRes