-
Notifications
You must be signed in to change notification settings - Fork 0
/
echo-service.ts
25 lines (22 loc) · 1.01 KB
/
echo-service.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
import { Mount } from "example/app-init";
import { Request } from "express";
import { All, createRequestInjector, Req, Service } from "src/index";
const This = createRequestInjector(() => (req, res, next, cxt) => cxt);
@Mount("/echo")
@Service()
class EchoService {
@All("*", { accept: "text/html", responseType: "raw" })
public async echoHtml(@Req req: Request, @This context: any) {
const { query, body, path, originalUrl: url, baseUrl, protocol, cookies, ip, hostname, headers } = req;
return `<h1>Echo Service!</h1><pre>${JSON.stringify(
{ path, url, baseUrl, protocol, cookies, ip, hostname, headers, query, body, context },
undefined,
2
)}</pre>`;
}
@All("*", { accept: "application/json", responseType: "json" })
public async echoJson(@Req req: Request, @This context: any) {
const { query, body, path, originalUrl: url, baseUrl, protocol, cookies, ip, hostname, headers } = req;
return { path, url, baseUrl, protocol, cookies, ip, hostname, headers, query, body, context };
}
}