-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.d.ts
159 lines (140 loc) · 3.93 KB
/
types.d.ts
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import {App, Component} from "vue";
import {HeadClient} from "@vueuse/head";
import {Router} from "vue-router";
import {Store} from "vuex";
import {SSRContext} from "@vue/server-renderer";
import {Connect, ViteDevServer} from "vite";
export interface PluginOptions {
name?:string, // plugin name, default: vite-ssr-vue
ssr?: string, // way to server entry point, if you want to use this separately
/**
* way to custom entry points
* used for build production chunk
* * for develop custom implementation must be used
*/
custom?: {
ws?: string,
[key: string]: string
}
// Custom serve middleware
serve?: (server: ViteDevServer, options: PluginOptionsInternal) => Connect.NextHandleFunction,
[key: string]: any
}
// Plugin options with addition params
export interface PluginOptionsInternal extends PluginOptions {
name:string,
wrappers: {
client:string,
server:string
}
}
export type SsrHandler = (
App: Component,
options?: CreatorOptions
) => SsrRenderer
export type ClientHandler = (
App: Component,
options?: CreatorOptions
) => Promise<void>
export interface CreatorOptions {
created?:Hook, // Fire when app instance created
mounted?:Hook, // Fire after all internal operations, as router isReady
rendered?:Hook, // After ssr rendered or after replace state in client
serializer?: ( // allows you to override the default serialization
state: any
) => any | Promise<any>,
// shouldPreload aka [shouldPreload](https://ssr.vuejs.org/api/#shouldpreload)
shouldPreload?:(file: string, type: string) => boolean,
// shouldPrefetch aka [shouldPrefetch](https://ssr.vuejs.org/api/#shouldprefetch)
shouldPrefetch?:(file: string, type: string) => boolean,
mount?: { // vue mount options (for client side)
rootContainer?:any,
isHydrate?: boolean,
isSVG?: boolean
},
rootProps?:Record<string, any>|null // vue root props
}
// Wrapper for ssr render
export type SsrRenderer = (
url: string | URL,
options?: {
manifest?: Record<string, string[]>,
[key: string]: any
}
) => Promise<{ html: string; dependencies: string[] }>
// Created hook params
export type Hook = (params: {
app: App
url: URL | Location
isClient: boolean
initialState: Record<string, any>,
context?: Context,
[key: string]: any
}) => HookResponse | Promise<HookResponse>
/**
* Created hook response
* If the parameter is returned, the default action is enabled
* examle: if you return store,
* auto add initialState
* you can override this behavior(if you don’t return the store)
*/
type HookResponse = void | {
head?: HeadClient,
router?:Router,
store?:Store<any>,
inserts?: {
htmlAttrs?:string,
headTags?:string,
bodyAttrs?:string,
body?:string,
dependencies?:Array<string>
},
context?:SSRContext
}
/**
* Context that used for render server entry point for development
* It needs a production implementation for your environment.
* The context will go to the created hook parameters of the plugin
*/
export interface Context {
/**
* hostname (example.com)
* as express req.hostname
*/
hostname: string,
/**
* protocol (http)
* as express req.protocol
*/
protocol: string,
/**
* string current url
* /search?q=something
*/
url: string,
/**
* this property is an object that contains cookies sent by the request
*/
cookies: Record<string, any>,
/**
* remote address (127.0.0.1)
*/
ip: string,
/**
* special property for usin memcached
*/
memcache: number|null,
/**
* response status code
* default 200
*/
statusCode: number,
/**
* Request headers
*/
headers: Record<string, any>,
/**
* Response headers
*/
responseHeaders: Record<string, any>,
}