-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (25 loc) · 727 Bytes
/
server.js
File metadata and controls
31 lines (25 loc) · 727 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
import express from 'express';
import axios from 'axios';
import cors from 'cors';
const app = express();
const PORT = process.env.PORT || 5000;
app.use(express.json());
app.use(cors()); // Enable CORS for all routes
app.get('/distance', async (req, res) => {
const { origins, destinations, key } = req.query;
try {
const response = await axios.get(`https://maps.googleapis.com/maps/api/distancematrix/json`, {
params: {
origins: origins,
destinations: destinations,
key: key,
}
});
res.json(response.data);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});