-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (26 loc) · 1.34 KB
/
Copy pathserver.js
File metadata and controls
35 lines (26 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
NEXT_PUBLIC_SUPABASE_ANON_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImliYWZ1aW9tYXBmaGZocnRscnVyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njk1MjczNTUsImV4cCI6MjA4NTEwMzM1NX0.FldhksdJzalyibyaChWncFFY5WTTx6IJrPl3I6oXGcA"
const express = require('express');
const { createClient } = require('@supabase/supabase-js');
const cors = require('cors');
const bodyParser = require('body-parser');
const app = express();
const port = process.env.PORT || 3000;
// Initialize Supabase client
const supabase = createClient('https://your-supabase-url.supabase.co', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImliYWZ1aW9tYXBmaGZocnRscnVyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njk1MjczNTUsImV4cCI6MjA4NTEwMzM1NX0.FldhksdJzalyibyaChWncFFY5WTTx6IJrPl3I6oXGcA');
// Middleware
app.use(cors());
app.use(bodyParser.json());
// Routes
app.post('/api/subscribe', async (req, res) => {
const { name, email, proof } = req.body;
// Insert subscription data into Supabase
const { data, error } = await supabase.from('subscriptions').insert([{ name, email, proof }]);
if (error) {
return res.status(400).json({ message: 'Error subscribing', error });
}
res.status(200).json({ message: 'Subscription successful', data });
});
// Start server
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});