Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
fix(koa): do not depend on named exports order when iterating middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrossmann committed Jan 16, 2019
1 parent d75862b commit d28b2d9
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/koa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import forcehttps from './forcehttps'
import routes from './routes'
import notfound from './notfound'

export {
export default {
forcehttps,
routes,
notfound,
Expand Down
2 changes: 1 addition & 1 deletion packages/koa/src/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class KoaService extends Service {
if (this.config.middleware) {
middleware(
koa,
this.atlas.require(this.config.middleware.module),
this.atlas.require(this.config.middleware.module, { normalise: true }),
this.config.middleware.config,
)
}
Expand Down
6 changes: 5 additions & 1 deletion packages/koa/src/websocket.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ class WebsocketHook extends Hook {

// Apply websocket middleware
if (config.middleware) {
middleware(koa.ws, this.atlas.require(config.middleware.module), config.middleware.config)
middleware(
koa.ws,
this.atlas.require(config.middleware.module, { normalise: true }),
config.middleware.config,
)
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/koa/test/server/prepare.test.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path'
import * as Koa from 'koa'
import { Server as Service } from '../..'
import * as testmiddleware from './testmiddleware'
import testmiddleware from './testmiddleware'

describe('Koa::prepare()', () => {
let service
Expand All @@ -14,7 +14,7 @@ describe('Koa::prepare()', () => {
this.sandbox.stub(Koa.prototype, 'use')
atlas = {
// eslint-disable-next-line global-require
require: location => require(path.resolve(__dirname, location)),
require: location => require(path.resolve(__dirname, location)).default,
}
config = {
middleware: {
Expand Down
2 changes: 1 addition & 1 deletion packages/koa/test/server/testmiddleware.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const first = sinon.stub()
const second = sinon.stub()

export {
export default {
first,
second,
}
4 changes: 2 additions & 2 deletions packages/koa/test/websocket/api.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from 'path'
import { Atlas } from '@atlas.js/atlas'
import Hook from '@atlas.js/hook'
import { WebsocketHook } from '../..'
import * as testmiddleware from './testmiddleware'
import testmiddleware from './testmiddleware'

describe('Hook: WebsocketHook', () => {
it('exists', () => {
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('Hook: WebsocketHook', () => {
config,
atlas: {
// eslint-disable-next-line global-require
require: location => require(path.resolve(__dirname, location)),
require: location => require(path.resolve(__dirname, location)).default,
},
log: { debug: () => {} },
component: () => koa,
Expand Down
2 changes: 1 addition & 1 deletion packages/koa/test/websocket/testmiddleware.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const first = sinon.stub()
const second = sinon.stub()

export {
export default {
first,
second,
}

0 comments on commit d28b2d9

Please sign in to comment.