Skip to content

Commit

Permalink
change env variable for functions
Browse files Browse the repository at this point in the history
  • Loading branch information
danhartley committed May 24, 2024
1 parent 277abe3 commit 1b605cd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
47 changes: 47 additions & 0 deletions public/netlify/functions/storeFieldnotes.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { getStore } from "@netlify/blobs"

export default async (request, context) => {
const store = getStore('ifieldnotes')
const id = context.id

if (request.method === 'POST') {
try {
const body = await request.text()
await store.set(id, body)
return new Response('HTML fragment stored', { status: 200 })
} catch (error) {
console.error(error)
return new Response(JSON.stringify({ error: 'Failed to store HTML fragment' }), { status: 500 })
}
} else if (request.method === 'GET') {
try {
const fragment = await store.get(id)
if (fragment) {
return new Response(fragment, { status: 200, headers: { 'Content-Type': 'text/html' } })
} else {
return new Response(JSON.stringify({ error: 'Fragment not found' }), { status: 404 })
}
} catch (error) {
console.error(error)
return new Response(JSON.stringify({ error: 'Failed to retrieve HTML fragment' }), { status: 500 })
}
} else {
return new Response(JSON.stringify({ error: 'Method Not Allowed' }), { status: 405 })
}
}



// import { getStore } from "@netlify/blobs"

// export default async (request, context) => {
// try {
// const construction = getStore('fieldnotes')
// await construction.set(request.fieldnotesId, request.article)

// return new Response('Article stored')
// } catch (error) {
// console.log(error)
// return Response.json({ error: 'Failed converting article to blob' }, { status: 500 })
// }
// }
4 changes: 2 additions & 2 deletions public/ui-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ export const updateHistoryAndTitle = ({window, slug, title}) => {
}

export const storeFieldnotes = async ({id, article}) => {
const url = `${process.env.URL}/netlify/functions/storeFieldnotes`
const url = `${process.env.FUNCTIONS_URL}/netlify/functions/storeFieldnotes`
const response = await fetch(url, {
method: 'POST',
headers: {
Expand All @@ -1374,7 +1374,7 @@ export const storeFieldnotes = async ({id, article}) => {
}

export const getFieldnotesFromStore = async ({id}) => {
const url = `${process.env.URL}/netlify/functions/storeFieldnotes`
const url = `${process.env.FUNCTIONS_URL}/netlify/functions/storeFieldnotes`
const response = await fetch(url, {
method: 'GET',
headers: {
Expand Down

0 comments on commit 1b605cd

Please sign in to comment.