quasar

Форк
0
/
ssrmiddleware.d.ts 
144 строки · 4.0 Кб
1
import { Express, Request, RequestHandler, Response, NextFunction } from "express";
2
import { Server } from "http";
3
import { Server as HttpsServer } from "https";
4
import { ServeStaticOptions } from "serve-static";
5

6
interface RenderParams {
7
  req: Request;
8
  res: Response;
9
}
10

11
interface RenderVueParams extends RenderParams, Record<string, any> {}
12

13
interface RenderError extends Error {
14
  code: Response["statusCode"];
15
  url: Request["url"];
16
}
17

18
interface RenderErrorParams extends RenderParams {
19
  err: RenderError;
20
}
21

22
interface SsrMiddlewareServe {
23
  /**
24
   * It's essentially a wrapper over express.static() with a few convenient tweaks:
25
   * - the pathFromPublicFolder is a path resolved to the "public" folder out of the box
26
   * - the opts are the same as for express.static()
27
   * - opts.maxAge is used by default, taking into account the quasar.config file > ssr > maxAge configuration; this sets how long the respective file(s) can live in browser's cache
28
   */
29
  static(
30
    path: string,
31
    options?: ServeStaticOptions<Response>
32
  ): RequestHandler<Response>;
33
  /**
34
   * Displays a wealth of useful debug information (including the stack trace).
35
   * Warning: It's available only in development and NOT in production.
36
   */
37
  error(ssrContext: RenderErrorParams): void;
38
}
39

40
type SsrMiddlewareRender = (ssrContext: RenderVueParams) => Promise<string>;
41

42
interface SsrMiddlewareFolders {
43
  root: string;
44
  public: string;
45
}
46

47
interface SsrMiddlewareResolve {
48
  /**
49
   * Whenever you define a route (with app.use(), app.get(), app.post() etc), you should use the resolve.urlPath() method so that you'll also keep into account the configured publicPath (quasar.config file > build > publicPath).
50
   */
51
  urlPath(url: string): string;
52
  /**
53
   * Resolve folder path to the root (of the project in dev and of the distributables in production). Under the hood, it does a path.join()
54
   * @param paths paths to join
55
   */
56
  root(...paths: string[]): string;
57
  /**
58
   * Resolve folder path to the "public" folder. Under the hood, it does a path.join()
59
   * @param paths paths to join
60
   */
61
  public(...paths: string[]): string;
62
}
63

64
interface SsrCreateParams {
65
  /**
66
   * Terminal PORT env var or the default configured port
67
   * for the SSR webserver
68
   */
69
  port: number;
70
  resolve: SsrMiddlewareResolve;
71
  publicPath: string;
72
  folders: SsrMiddlewareFolders;
73
  /**
74
   * Uses Vue and Vue Router to render the requested URL path.
75
   * @returns the rendered HTML string to return to the client
76
   */
77
  render: SsrMiddlewareRender;
78
  serve: SsrMiddlewareServe;
79
}
80

81
export type SsrCreateCallback = (
82
  params: SsrCreateParams
83
) => Express | any;
84

85
interface SsrMiddlewareParams extends SsrCreateParams {
86
  app: Express;
87
}
88

89
export type SsrMiddlewareCallback = (
90
  params: SsrMiddlewareParams
91
) => void | Promise<void>;
92

93
interface SsrHandlerParams {
94
  req: Request;
95
  res: Response;
96
  next: NextFunction;
97
}
98

99
interface SsrListenParams extends SsrMiddlewareParams {
100
  /**
101
   * Wait for app to be initialized (run all SSR middlewares)
102
   * before starting to listen for clients
103
   */
104
  isReady(): Promise<void>;
105
  /**
106
   * If you use HTTPS in development, this will be the
107
   * actual server that listens for clients.
108
   * It is a Node https.Server instance wrapper over the original "app".
109
   */
110
  devHttpsApp?: HttpsServer;
111
  /**
112
   * SSR handler to be used on production should
113
   * you wish to use a serverless approach.
114
   */
115
  ssrHandler(
116
    params: SsrHandlerParams
117
  ): Promise<void>;
118
}
119

120
export type SsrListenCallback = (
121
  params: SsrListenParams
122
) => Promise<Server>;
123

124
interface SsrCloseParams extends SsrListenParams {
125
  listenResult: Server;
126
}
127

128
export type SsrCloseCallback = (
129
  params: SsrCloseParams
130
) => void;
131

132
export type SsrServeStaticContentCallback = (
133
  path: string,
134
  opts?: ServeStaticOptions<Response>
135
) => RequestHandler<Response>;
136

137
interface SsrRenderPreloadTagCallbackOptions {
138
  ssrContext: RenderVueParams;
139
}
140

141
export type SsrRenderPreloadTagCallback = (
142
  file: string,
143
  options: SsrRenderPreloadTagCallbackOptions
144
) => string;
145

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.