-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
44 lines (39 loc) · 1.03 KB
/
app.ts
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
44
import * as express from 'express';
import { Express, Request, Response } from 'express-serve-static-core';
import * as queryString from 'querystring';
import fetch from 'node-fetch';
const app: Express = express();
const apiKey: string = '';
type QueryObj = {
origin: string;
destination: string;
key: string;
mode: string;
language: string;
region: string;
};
app.get(
'/',
(req: Request, res: Response): void => {
const queryObj: QueryObj = {
origin: req.query.origin,
destination: req.query.destination,
key: apiKey,
mode: req.query.mode,
language: req.query.language,
region: req.query.region,
};
const stringQuery: string = queryString.stringify(queryObj);
fetch(`https://maps.googleapis.com/maps/api/directions/json?${stringQuery}`)
.then(mapRes => {
return mapRes.json();
})
.then(
(json: Response): Response => {
return res.send(json);
}
)
.catch((err: Error) => console.log(err));
}
);
app.listen(5000);