XciD HF Staff commited on
Commit
57291f1
·
verified ·
1 Parent(s): d2b0c1e

Create server.js

Browse files
Files changed (1) hide show
  1. server.js +24 -0
server.js ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const app = express();
3
+ app.use(express.json());
4
+
5
+ app.post('/shipping-rates', (req, res) => {
6
+ console.log(req.body);
7
+ console.log(req.body.rate.items[0]);
8
+
9
+ // Compute the weight of all items
10
+ const weight = req.body.rate.items.reduce((acc, item) => acc + item.grams, 0);
11
+ console.log(weight);
12
+
13
+
14
+ res.json({ "rates": [ {
15
+ "service_name": "Transporteur privée",
16
+ "service_code": "CA",
17
+ "total_price": "1295",
18
+ "description": "",
19
+ "currency": "EUR"
20
+ },
21
+ ]});
22
+ });
23
+
24
+ app.listen(3000, () => console.log('Shipping API running on port 3000'));