submits correctly now using variables set in the service from secrets.
This commit is contained in:
+1
-1
@@ -202,7 +202,7 @@
|
|||||||
data.pbToken = pb.authStore.token;
|
data.pbToken = pb.authStore.token;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/idea-feedback/api/submit', {
|
const response = await fetch('/api/submit', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
"description": "Idea and Feedback Form with PocketBase",
|
"description": "Idea and Feedback Form with PocketBase",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "bun run server.ts",
|
"dev": "PORT=7001 bun run server.ts",
|
||||||
"start": "bun run server.ts"
|
"start": "bun run server.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -2,9 +2,6 @@ import { Hono } from 'hono';
|
|||||||
import { serveStatic } from 'hono/bun';
|
import { serveStatic } from 'hono/bun';
|
||||||
import { cors } from 'hono/cors';
|
import { cors } from 'hono/cors';
|
||||||
import PocketBase from 'pocketbase';
|
import PocketBase from 'pocketbase';
|
||||||
import { config } from 'dotenv';
|
|
||||||
|
|
||||||
config();
|
|
||||||
|
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
|
|
||||||
@@ -14,9 +11,12 @@ app.use('/*', cors());
|
|||||||
// Serve static files from frontend directory
|
// Serve static files from frontend directory
|
||||||
app.use('/*', serveStatic({ root: './frontend' }));
|
app.use('/*', serveStatic({ root: './frontend' }));
|
||||||
|
|
||||||
// PocketBase client
|
// PocketBase client - PB_DB from service environment
|
||||||
const pb = new PocketBase(process.env.PB_DB || 'https://pocketbase.ccllc.pro');
|
const pb = new PocketBase(process.env.PB_DB || 'https://pocketbase.ccllc.pro');
|
||||||
|
|
||||||
|
// Collection name from service env (fallback to Ideas_Feedback)
|
||||||
|
const PB_IDEA_COLLECTION = process.env.PBIdea_Collection || 'Ideas_Feedback';
|
||||||
|
|
||||||
// Use user's PocketBase token (passed from authenticated frontend)
|
// Use user's PocketBase token (passed from authenticated frontend)
|
||||||
function setUserPocketBaseAuth(token: string) {
|
function setUserPocketBaseAuth(token: string) {
|
||||||
pb.authStore.save(token);
|
pb.authStore.save(token);
|
||||||
@@ -41,7 +41,7 @@ app.post('/api/submit', async (c) => {
|
|||||||
delete data.pbToken;
|
delete data.pbToken;
|
||||||
|
|
||||||
// Create the record in PocketBase as the authenticated user
|
// Create the record in PocketBase as the authenticated user
|
||||||
const record = await pb.collection(process.env.PB_COLLECTION!).create(data);
|
const record = await pb.collection(PB_IDEA_COLLECTION).create(data);
|
||||||
console.log(`✓ Created PocketBase record with ID: ${record.id}`);
|
console.log(`✓ Created PocketBase record with ID: ${record.id}`);
|
||||||
|
|
||||||
return c.json({
|
return c.json({
|
||||||
|
|||||||
Reference in New Issue
Block a user