From a6ddedc20f8171a090e05ffbb1b102525fba515a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 30 Mar 2023 11:29:02 +0200 Subject: [PATCH] Update default Content-Type to reflect the one used by `cable_ready` Since https://github.com/stimulusreflex/cable_ready/pull/260, `cable_ready` changed its Content-Type to `text/vnd.cable-ready.json`. This commit updates the default one used to be compatible with `cable_ready`. --- docs/src/_documentation/how_tos/05-integrate-cablecar.md | 4 ++-- plugins/src/cableCar.ts | 2 +- test/js/plugins/cableCar.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/src/_documentation/how_tos/05-integrate-cablecar.md b/docs/src/_documentation/how_tos/05-integrate-cablecar.md index 79adfeb5..7846d32b 100644 --- a/docs/src/_documentation/how_tos/05-integrate-cablecar.md +++ b/docs/src/_documentation/how_tos/05-integrate-cablecar.md @@ -38,12 +38,12 @@ mrujs.start({ Now, any link or form with `data-method=""` or `data-remote="true"` will have the following `Accept` header: ```js -"application/vnd.cable-ready.json, */*" +"text/vnd.cable-ready.json, */*" ``` which means any link or form with `data-method=""` or `data-remote="true"` will perform an AJAX request, return JSON if it finds a CableCar response from your Rails -server (or any Ruby server which provides a `Content-Type: application/vnd.cable-ready.json` +server (or any Ruby server which provides a `Content-Type: text/vnd.cable-ready.json` header), and then automatically perform CableCar operations defined in the JSON payload return. diff --git a/plugins/src/cableCar.ts b/plugins/src/cableCar.ts index bd1bb296..b5c99073 100644 --- a/plugins/src/cableCar.ts +++ b/plugins/src/cableCar.ts @@ -13,7 +13,7 @@ export class CableCar { constructor (cableReady: CableReady, { mimeType }: CableCarConfig = {}) { this.cableReady = cableReady - this.mimeType = (mimeType ?? 'application/vnd.cable-ready.json') + this.mimeType = mimeType ?? "text/vnd.cable-ready.json"; this.boundPerform = this.perform.bind(this) as EventListener } diff --git a/test/js/plugins/cableCar.ts b/test/js/plugins/cableCar.ts index 257da35e..74419020 100644 --- a/test/js/plugins/cableCar.ts +++ b/test/js/plugins/cableCar.ts @@ -15,7 +15,7 @@ describe('CableCar with standard config', () => { }) it('Should return true for the given content type', () => { - assert(cableCar.isCableReadyResponse("application/vnd.cable-ready.json; charset='utf-8'")) + assert(cableCar.isCableReadyResponse("text/vnd.cable-ready.json; charset='utf-8'")) }) it('Should return true for the given content type', () => {