Skip to content

Commit df56918

Browse files
authored
fix(core): Allow services with no external methods (#2921)
1 parent d9449fa commit df56918

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/feathers/src/service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ export function wrapService(location: string, service: any, options: ServiceOpti
6363
const protoService = Object.create(service)
6464
const serviceOptions = normalizeServiceOptions(service, options)
6565

66-
if (Object.keys(serviceOptions.methods).length === 0 && typeof service.setup !== 'function') {
66+
if (
67+
Object.keys(serviceOptions.methods).length === 0 &&
68+
![...defaultServiceMethods, 'setup', 'teardown'].some((method) => typeof service[method] === 'function')
69+
) {
6770
throw new Error(`Invalid service object passed for path \`${location}\``)
6871
}
6972

packages/feathers/test/application.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ describe('Feathers application', () => {
165165
)
166166
})
167167

168+
it('can register service with no external methods', async () => {
169+
const dummyService = {
170+
async create(data: any) {
171+
return data
172+
}
173+
}
174+
175+
feathers().use('dummy', dummyService, {
176+
methods: []
177+
})
178+
})
179+
168180
it('can use a root level service', async () => {
169181
const app = feathers().use('/', {
170182
async get(id: string) {

0 commit comments

Comments
 (0)