sveltejs / api.svelte.dev

The API worker source for https://api.svelte.dev
14 stars 4 forks source link

JSON responses are being served with `content-type: text/plain` #15

Closed Rich-Harris closed 2 years ago

Rich-Harris commented 2 years ago

https://api.svelte.dev/docs/svelte/tutorial/introduction-basics. Easy enough to add in https://github.com/sveltejs/api.svelte.dev/blob/master/src/routes/docs.ts but maybe there's a neater/more comprehensive solution

lukeed commented 2 years ago

The docs model is saving and serving text instead of JSON: https://github.com/sveltejs/api.svelte.dev/blob/master/src/models/docs.ts#L10

So when worktop sees & sends the docs value it's already a string & worktop skips the auto-cast to JSON and doesn't auto-apply the header: https://github.com/sveltejs/api.svelte.dev/blob/master/src/routes/docs.ts#L22

This was probably done for performance optimization and/or a result of data migration. If not I'd recommend the KV store deal with JSON values. Otherwise send a custom headers object to last res.send method