Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions courses/service-course/steps/04_clients-analytics/pt.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,68 @@ Neste passo, vamos implementar o cliente de _Analytics_.
await next()
}
```

7. Agora é necessário fazer que a aplicação importe e registre o Client do analytics recém criado. Dessa forma, teremos uma rota para acessá-lo. É comum que façamos isso no arquivo `index.ts` da pasta `/node` :
```diff
// node/index.ts
import {
...
+ method,
...

...
+import { Clients } from './clients'
+import { analytics } from './handler/analytics'
...

...
-type Context = ServiceContext<IOClients, State>
-type Context = ServiceContext<Clients, State>
...

...
-export default new Service<IOClients, State, ParamsContext>({
+export default new Service<Clients, State, ParamsContext>({
...

clients: {
...
+implementation: Clients,
...
options: {
...
+ default: {
+ retries: 2,
+ timeout: 10000,
+ },
...

...
routes: {
hcheck: (ctx: any) => {
setCacheContext(ctx)
ctx.set('Cache-Control', 'no-cache')
ctx.status = 200
ctx.body = 'ok'
},
+analytics: method({
+ GET: [analytics]
+}),
...
```

4. Também é necessário modificar o arquivo `service.json` e incluir a rota ao serviço.

```diff
//node/service.json
},
...
+"routes": {
+ "analytics": {
+ "path": "/_v/app/events-example/analytics",
+ "public": true
+ }
```

Agora, vamos testá-lo! É possível utilizar o Postman para enviar um _request_ GET para a seguinte rota:

Expand Down