22 lines
581 B
JavaScript
22 lines
581 B
JavaScript
|
export const useEtherpadApi = () => {
|
||
|
const { baseUrl } = useRuntimeConfig().public
|
||
|
const etherpadApiUrl = `${baseUrl}/etherpad-api`
|
||
|
|
||
|
const etherFetch = (path, params) => {
|
||
|
|
||
|
// Convert to form key-value pairs
|
||
|
const formBody = Object.keys(params)
|
||
|
.map(key => `${key}=${encodeURIComponent(params[key])}`)
|
||
|
.join('&')
|
||
|
|
||
|
// Call API
|
||
|
return $fetch(etherpadApiUrl + path, {
|
||
|
method: 'POST',
|
||
|
headers: {'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'},
|
||
|
body: formBody
|
||
|
})
|
||
|
}
|
||
|
|
||
|
return { etherpadApiUrl, etherFetch }
|
||
|
}
|