diff --git a/public/App.svelte b/public/App.svelte index 32310b7..c939d43 100644 --- a/public/App.svelte +++ b/public/App.svelte @@ -50,11 +50,22 @@ loading = false; } - const selectDb = async (tenant) => { + const selectDb = async (tenant) => { + console.log("selecting tenant",tenant); loading = true; currentTenant = tenant; - data = await fetch('d1/'+tenant.name); + console.log(`fetching d1/${tenant.name}`); + let response = await fetch('d1/'+tenant.name); + console.log(response); + if (response.status == 200) { + var payload = await response.text(); + console.log(payload); + var dat = JSON.parse(payload); + console.log(dat); + data = dat; + } loading = false; + console.log('db selected'); } const createDb = async () => { @@ -73,9 +84,10 @@ "id":dataId, "data":dataValue }; - await fetch('d1/'+currentTenant.name,{method:"POST", body:JSON.stringify(payload)}); + await fetch('d1/'+currentTenant.name,{method:"PUT", body:JSON.stringify(payload)}); dataId=""; dataValue=""; + await selectDb(currentTenant); loading = false; } diff --git a/public/_worker.js b/public/_worker.js index 8fdfc57..1642200 100644 --- a/public/_worker.js +++ b/public/_worker.js @@ -156,13 +156,13 @@ router.get('/d1/:tenant', withParams, async (request, env) => { // add a data row for a given tenant // should be a PUT -router.post('/d1/:tenant', withParams, withContent, async (request, env) => { +router.put('/d1/:tenant', withParams, withContent, async (request, env) => { try { var tenant = request.params.tenant var data = await request.json() console.log('*************************************') console.log('*************************************') - var d1Fromcontext = context.env[tenant] + var d1Fromcontext = env[tenant.toUpperCase()] console.log('d1Fromcontext', d1Fromcontext) await d1Fromcontext .prepare(