-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (81 loc) · 2.36 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"use strict";
var __awaiter =
(this && this.__awaiter) ||
function (thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P
? value
: new P(function (resolve) {
resolve(value);
});
}
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done
? resolve(result.value)
: adopt(result.value).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = __importDefault(require("express"));
const body_parser_1 = __importDefault(require("body-parser"));
const cors_1 = __importDefault(require("cors"));
const dotenv_1 = __importDefault(require("dotenv"));
const client_1 = require("@prisma/client");
const app = (0, express_1.default)();
const port = process.env.SERVER_PORT;
const prisma = new client_1.PrismaClient();
dotenv_1.default.config();
app.use(body_parser_1.default.json());
app.use("*", (0, cors_1.default)());
app.options("/batch-geocode", (0, cors_1.default)());
app.get("/", (req, res) => {
res.json({ message: "hello from geocoding API" });
});
app.post("/batch-geocode", (req, res) =>
__awaiter(void 0, void 0, void 0, function* () {
console.log("req.body is..", req.body);
const { geo_locations } = req.body;
// console.log("geo_locations are...", geo_locations);
const geojson = yield prisma.geojson.findMany({
where: {
OR: [
{
full_name: {
in: geo_locations,
},
},
{ iso_name: { in: geo_locations } },
],
},
});
// console.log("geojson is...", geojson);
res.status(200);
res.json(geojson);
})
);
app.listen(port, () => {
console.log(`[server]: Server is running at http://localhost:${port}`);
});
exports.default = app;