Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export class ResponseFormatMiddleware extends BuiltInMiddleware<ResponseFormatOp
public async handle(context: KoaContext, next: Next) {
// return to skip the middleware, if disabled
if (!this.enabled) return next();
// TODO: replace the hardcoded api with configurable prefix
// Only handle the path for Vulcan API
if (!context.request.path.startsWith('/api')) return next();

// get supported and request format to use.
const format = checkUsableFormat({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as sinon from 'ts-sinon';
import { ResponseFormatMiddleware } from '@vulcan-sql/serve/middleware';
import { BaseResponseFormatter } from '@vulcan-sql/serve';
import { BaseResponseFormatter, KoaContext } from '@vulcan-sql/serve';

describe('Test format response middleware', () => {
afterEach(() => {
Expand Down Expand Up @@ -218,4 +218,17 @@ describe('Test format response middleware', () => {
});

// TODO: test handle to get context response

it('Test to do nothing with paths which are not start in /api', async () => {
// Arrange
const middleware = new ResponseFormatMiddleware({}, '', []);
const mockContext = sinon.stubInterface<KoaContext>();
mockContext.request.path = '/favicon.ico';
mockContext.response.body = '123';
// Act
await middleware.handle(mockContext, async () => null);

// Assert
expect(mockContext.response.body).toBe('123');
});
});