-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (36 loc) · 979 Bytes
/
index.js
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
36
37
38
39
40
41
42
43
const functions = require('firebase-functions');
const express = require('express');
const app = express();
app.use(express.json());
// Define your routes here similar to the Express.js API
let products = [];
let orders = [];
let accounting = [];
// Add new product
app.post('/products', (req, res) => {
const product = req.body;
products.push(product);
res.send({ message: 'Product added', product });
});
// List all products
app.get('/products', (req, res) => {
res.send(products);
});
// Add new order
app.post('/orders', (req, res) => {
const order = req.body;
orders.push(order);
res.send({ message: 'Order placed', order });
});
// List all orders
app.get('/orders', (req, res) => {
res.send(orders);
});
// Manage accounting data
app.post('/accounting', (req, res) => {
const entry = req.body;
accounting.push(entry);
res.send({ message: 'Accounting entry added', entry });
});
// Export the API
exports.api = functions.https.onRequest(app);