Skip to content

Commit 6177d07

Browse files
committed
refactor: migrate catalog service initialization to kdk-map-api and update dynamic service configuration
1 parent 25ec394 commit 6177d07

2 files changed

Lines changed: 29 additions & 17 deletions

File tree

packages/katalog/src/server.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import configuration from '@feathersjs/configuration'
1212
import { logger } from './logger.js'
1313
import { mongodb } from './mongodb.js'
1414
import { services } from './services/index.js'
15-
import { createDefaultCatalogLayers } from './services/catalog/catalog.init.js'
15+
import { createDefaultCatalogLayers } from '@kalisio/kdk-map-api'
1616

1717
export class Server {
1818
constructor () {
@@ -24,11 +24,8 @@ export class Server {
2424
this.app.use(urlencoded({ extended: true }))
2525

2626
this.app.configure(rest())
27-
2827
this.app.configure(mongodb)
2928

30-
this.app.configure(services)
31-
3229
this.app.use(notFound())
3330
this.app.use(errorHandler({ logger }))
3431

@@ -38,21 +35,13 @@ export class Server {
3835
after: {},
3936
error: {}
4037
})
41-
42-
this.app.hooks({
43-
setup: [
44-
async (context) => {
45-
await createDefaultCatalogLayers(context.app)
46-
}
47-
],
48-
teardown: []
49-
})
5038
}
5139

5240
async run () {
5341
const port = this.app.get('port')
5442
const host = this.app.get('host')
55-
43+
await services(this.app)
44+
await createDefaultCatalogLayers.call(this.app)
5645
await this.app.listen(port)
5746
logger.info(`Feathers app listening on http://${host}:${port}`)
5847
}
Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
1-
import { catalog } from './catalog/catalog.service.js'
2-
export const services = app => {
3-
app.configure(catalog)
1+
import { createCatalogService } from '@kalisio/kdk-map-api'
2+
import { MongoDBService } from '@feathersjs/mongodb'
3+
4+
export const services = async app => {
5+
app.getService = (name) => {
6+
try {
7+
return app.service(name)
8+
} catch {
9+
return null
10+
}
11+
}
12+
13+
app.createService = async (name, options) => {
14+
const db = await app.get('mongodbClient')
15+
options.Model = db.collection(name)
16+
app.use(name, new MongoDBService(options))
17+
const service = app.service(name)
18+
service.options = options
19+
return service
20+
}
21+
22+
if (!app.logger) {
23+
app.logger = { info: console.log, warn: console.warn, error: console.error, debug: console.debug }
24+
}
25+
26+
await createCatalogService.call(app)
427
}

0 commit comments

Comments
 (0)