Add Insomnia export and dynamic hostname for API doc
Insomnia export (/api/doc/insomnia.json):
- Generates Insomnia v4 export format with all API routes
- Workspace with environment variables (base_url, env, email, password, jwt_token)
- Folders per section (Auth, Events, Categories, Billets, Scanner)
- Each request with correct method, URL with Insomnia template vars, headers, body
- Auth routes use base_url directly, others use base_url/api/{env}/...
- Download button (indigo) next to Spec JSON button
Dynamic hostname:
- Insomnia export uses request.getSchemeAndHttpHost() (not hardcoded)
- Template passes host via data-host attribute
- JS env switcher reads host from data-host or falls back to location.origin
- Base URLs update dynamically when switching sandbox/live
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,24 +1,26 @@
|
||||
const ENVS = {
|
||||
sandbox: {
|
||||
prefix: '/api/sandbox',
|
||||
baseUrl: 'https://ticket.e-cosplay.fr/api/sandbox',
|
||||
color: 'text-orange-400',
|
||||
btnBg: 'bg-orange-500',
|
||||
desc: 'Environnement de test. Les donnees ne sont pas modifiees.',
|
||||
},
|
||||
live: {
|
||||
prefix: '/api/live',
|
||||
baseUrl: 'https://ticket.e-cosplay.fr/api/live',
|
||||
color: 'text-green-400',
|
||||
btnBg: 'bg-green-600',
|
||||
desc: 'Environnement de production. Les donnees sont reelles.',
|
||||
},
|
||||
}
|
||||
|
||||
const BTN_BASE = 'env-btn px-5 py-2 font-black uppercase text-xs tracking-widest transition-all cursor-pointer '
|
||||
|
||||
function switchEnv(env) {
|
||||
const config = ENVS[env]
|
||||
function getEnvs(host) {
|
||||
return {
|
||||
sandbox: {
|
||||
prefix: '/api/sandbox',
|
||||
baseUrl: host + '/api/sandbox',
|
||||
color: 'text-orange-400',
|
||||
btnBg: 'bg-orange-500',
|
||||
desc: 'Environnement de test. Les donnees ne sont pas modifiees.',
|
||||
},
|
||||
live: {
|
||||
prefix: '/api/live',
|
||||
baseUrl: host + '/api/live',
|
||||
color: 'text-green-400',
|
||||
btnBg: 'bg-green-600',
|
||||
desc: 'Environnement de production. Les donnees sont reelles.',
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function switchEnv(env, envs) {
|
||||
const config = envs[env]
|
||||
if (!config) return
|
||||
|
||||
document.querySelectorAll('.env-btn').forEach(btn => {
|
||||
@@ -42,7 +44,11 @@ export function initApiEnvSwitcher() {
|
||||
const switcher = document.getElementById('env-switcher')
|
||||
if (!switcher) return
|
||||
|
||||
const hostEl = document.querySelector('[data-host]')
|
||||
const host = hostEl ? hostEl.dataset.host : globalThis.location.origin
|
||||
const envs = getEnvs(host)
|
||||
|
||||
document.querySelectorAll('.env-btn').forEach(btn => {
|
||||
btn.addEventListener('click', () => switchEnv(btn.dataset.env))
|
||||
btn.addEventListener('click', () => switchEnv(btn.dataset.env, envs))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user