Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing several changes on service and index.ts #142

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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