Skip to content

Commit

Permalink
refactor(cli): use routers defined in config (#381)
Browse files Browse the repository at this point in the history
* refactor(cli): use routers defined in config

* feat: static agent option: RequestWithAgentRouter

* test: fix rest integration tests

* feat: execute functions during server init

* fix(cli): bump supported config version number
  • Loading branch information
simonas-notcat authored Mar 9, 2021
1 parent 6c33c44 commit ec3367d
Show file tree
Hide file tree
Showing 15 changed files with 409 additions and 357 deletions.
9 changes: 6 additions & 3 deletions __tests__/restAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
import { AgentRestClient } from '../packages/remote-client/src'
import express from 'express'
import { Server } from 'http'
import { AgentRouter } from '../packages/remote-server/src'
import { AgentRouter, RequestWithAgentRouter } from '../packages/remote-server/src'
import { Resolver } from 'did-resolver'
import { getResolver as ethrDidResolver } from 'ethr-did-resolver'
import { getResolver as webDidResolver } from 'web-did-resolver'
Expand Down Expand Up @@ -159,13 +159,16 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
})

const agentRouter = AgentRouter({
getAgentForRequest: async (req) => serverAgent,
exposedMethods: serverAgent.availableMethods(),
})

const requestWithAgent = RequestWithAgentRouter({
agent: serverAgent,
})

return new Promise((resolve) => {
const app = express()
app.use(basePath, agentRouter)
app.use(basePath, requestWithAgent, agentRouter)
restServer = app.listen(port, () => {
resolve(true)
})
Expand Down
23 changes: 5 additions & 18 deletions packages/cli/default/client.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
version: 1.0
server:
hostname: localhost
port: 3335
schemaPath: /open-api.json
apiBasePath: /agent
apiDocsPath: /api-docs
defaultDID:
create: true
messagingServiceEndpoint: /messaging
ngrok:
connect: true
# authtoken: XZY
# subdomain: alice-did
# region: eu
# exposedMethods:
# - resolveDid
# - dataStoreORMGetIdentifiers
version: 2.0

agent:
$require: '@veramo/core#Agent'
$args:
Expand Down Expand Up @@ -48,8 +32,11 @@ agent:
- didManagerAddService
- didManagerRemoveService
- resolveDid
- dataStoreGetMessage
- dataStoreSaveMessage
- dataStoreGetVerifiableCredential
- dataStoreSaveVerifiableCredential
- dataStoreGetVerifiablePresentation
- dataStoreSaveVerifiablePresentation
- dataStoreORMGetIdentifiers
- dataStoreORMGetIdentifiersCount
Expand Down
Loading

0 comments on commit ec3367d

Please sign in to comment.