Skip to content

Commit

Permalink
fix(rest): routing fix and moved cors to dependencies (#31)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan <jan@animo.id>
  • Loading branch information
janrtvld committed Sep 17, 2021
1 parent 2686699 commit 0999658
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
21 changes: 21 additions & 0 deletions packages/rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,24 @@ Then add the rest package to your project.
```sh
yarn add @aries-framework/rest
```

### Quick start

> The OpenAPI spec is generated using the OpenAPI Schema (Swagger). However this schema is not representing the real API. A lot of types are not correct. Keep this in mind when using this package.
Aries Framework JavaScript REST API provides a Swagger (OpenAPI) definition of the exposed API. After you start the REST API the generated API Client will be available on `/docs`.

### Example of usage

```ts
import { startServer } from '@aries-framework/rest'

// The startServer function requires an initialized agent and a port.
// An example of how to setup an agent is located in the `samples` directory.
const run = async (agent: Agent) => {
await startServer(agent, 3000)
}

// A Swagger (OpenAPI) definition is exposed on http://localhost:3000/docs
run()
```
2 changes: 1 addition & 1 deletion packages/rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"class-validator-jsonschema": "^3.1.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"ngrok": "^4.2.2",
"reflect-metadata": "^0.1.13",
Expand All @@ -46,7 +47,6 @@
"@types/supertest": "^2.0.11",
"@types/swagger-ui-express": "^4.1.3",
"@types/uuid": "^8.3.1",
"cors": "^2.8.5",
"jest": "^27.1.0",
"patch-package": "^6.4.7",
"supertest": "^6.1.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/rest/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const setupServer = async (agent: Agent) => {
Container.set(Agent, agent)

const app: Express = createExpressServer({
controllers: [__dirname + '/controllers/**/*.ts'],
controllers: [__dirname + '/controllers/**/*.ts', __dirname + '/controllers/**/*.js'],
cors: true,
})

Expand Down

0 comments on commit 0999658

Please sign in to comment.