file: add files to server directory
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
.env
|
||||
node_modules
|
||||
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
const express = require("express");
|
||||
const cors = require("cors");
|
||||
require("dotenv").config();
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
|
||||
// routes
|
||||
app.use("/api/search", require("./routes/searchResults.js"));
|
||||
|
||||
// Handle Production
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
app.use(express.static(`${__dirname}/public`));
|
||||
}
|
||||
|
||||
const PORT = process.env.PORT || 3000;
|
||||
app.listen(PORT);
|
||||
Generated
+3203
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "geocoding-map",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "node index.js",
|
||||
"dev": "nodemon index.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "Leon Xu",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^0.24.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^10.0.0",
|
||||
"express": "^4.17.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.15"
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
@@ -0,0 +1 @@
|
||||
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="map-marker-alt" class="svg-inline--fa fa-map-marker-alt fa-w-12" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="#0000FF" d="M172.268 501.67C26.97 291.031 0 269.413 0 192 0 85.961 85.961 0 192 0s192 85.961 192 192c0 77.413-26.97 99.031-172.268 309.67-9.535 13.774-29.93 13.773-39.464 0zM192 272c44.183 0 80-35.817 80-80s-35.817-80-80-80-80 35.817-80 80 35.817 80 80 80z"></path></svg>
|
||||
|
After Width: | Height: | Size: 487 B |
@@ -0,0 +1 @@
|
||||
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="map-marker-alt" class="svg-inline--fa fa-map-marker-alt fa-w-12" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="#FF0000" d="M172.268 501.67C26.97 291.031 0 269.413 0 192 0 85.961 85.961 0 192 0s192 85.961 192 192c0 77.413-26.97 99.031-172.268 309.67-9.535 13.774-29.93 13.773-39.464 0zM192 272c44.183 0 80-35.817 80-80s-35.817-80-80-80-80 35.817-80 80 35.817 80 80 80z"></path></svg>
|
||||
|
After Width: | Height: | Size: 487 B |
@@ -0,0 +1 @@
|
||||
<!doctype html><html lang=""><head><meta charset="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="viewport" content="width=device-width,initial-scale=1"/><link rel="icon" href="/favicon.ico"/><link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A==" crossorigin=""/><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" crossorigin="anonymous" referrerpolicy="no-referrer"/><title>Geocoding App</title><script defer="defer" src="/js/chunk-vendors.b6d8a41d.js"></script><script defer="defer" src="/js/app.52c84516.js"></script><link href="/css/app.4f94ddf0.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but Geocoding App doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const axios = require("axios");
|
||||
const url = require("url");
|
||||
|
||||
router.get("/:query", async (req, res) => {
|
||||
try {
|
||||
// Add API key & query strings
|
||||
const params = new URLSearchParams({
|
||||
access_token: process.env.API_KEY,
|
||||
...url.parse(req.url, true).query,
|
||||
});
|
||||
const query = req.params.query;
|
||||
const results = await axios.get(
|
||||
`https://api.mapbox.com/geocoding/v5/mapbox.places/${query}.json?${params}`
|
||||
);
|
||||
|
||||
// format data to include city and state
|
||||
results.data.features.forEach((item) => {
|
||||
// init set to null
|
||||
item.city = null;
|
||||
item.state = null;
|
||||
|
||||
// cycle through content results
|
||||
item.context.forEach((type) => {
|
||||
if (type.id.includes("place")) {
|
||||
item.city = type.text;
|
||||
}
|
||||
if (type.id.includes("region")) {
|
||||
item.state = type.text;
|
||||
}
|
||||
});
|
||||
});
|
||||
const data = results.data;
|
||||
res.status(200).json(data);
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user