Clean master commit

This commit is contained in:
Lachlan Kermode
2018-10-31 19:35:15 +00:00
commit 2cbfbc33ef
24 changed files with 5400 additions and 0 deletions

17
src/middleware/index.js Executable file
View File

@@ -0,0 +1,17 @@
import {Router, next} from "express";
import {mapboxAccessToken} from "../config";
import morgan from "morgan";
import mapbox from "./mapbox";
export default ({config, db}) => {
let routes = Router();
/* logging middleware */
routes.use(morgan("dev"));
if (mapboxAccessToken) {
routes.get("/mapbox/:z/:y/:x", mapbox(mapboxAccessToken));
}
return routes;
};

View File

@@ -0,0 +1,16 @@
import fetch from "node-fetch";
import fs from "fs";
// TODO: load images from mapbox API and store.
const baseUrl = "http://a.tiles.mapbox.com/v4/mapbox.satellite";
export default accessToken => (req, res) => {
const {x, y, z} = req.params;
// const filename = `${z}-${y}-${x}.png`
// const fileStream = fs.createWriteStream(`${z}-${y}-${x}.png`)
fetch(
`http://a.tiles.mapbox.com/v4/mapbox.satellite/${z}/${y}/${x}@2x.png?access_token=${accessToken}`
).then(result => {
res.set("Content-Type", "image/png");
result.body.pipe(res);
});
};