-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndex
More file actions
32 lines (27 loc) · 940 Bytes
/
Index
File metadata and controls
32 lines (27 loc) · 940 Bytes
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
require('dotenv').config();
const Fastify = require('fastify');
const cors = require('@fastify/cors');
const { createClient } = require('@supabase/supabase-js');
const supabaseUrl = process.env.SUPABASE_URL;
const supabaseKey = process.env.SUPABASE_SERVICE_KEY;
const supabase = createClient(supabaseUrl, supabaseKey);
const app = Fastify({logger:true});
app.register(cors, { origin: true });
// health
app.get('/health', async (req, reply) => reply.send({ok:true}));
// example: get products
app.get('/v1/products', async (req, reply) => {
const { data, error } = await supabase.from('products').select('*').limit(100);
if (error) return reply.code(500).send({error});
return reply.send({data});
});
const start = async () => {
try {
await app.listen({ port: process.env.PORT || 3000, host: '0.0.0.0' });
app.log.info('Server listening');
} catch (err) {
app.log.error(err);
process.exit(1);
}
};
start();