Skip to content

Commit

Permalink
Update tile server to use updated mbtiles path
Browse files Browse the repository at this point in the history
  • Loading branch information
DingoEatingFuzz committed Oct 13, 2019
1 parent 7721712 commit 6d94db7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ app.use(cors());

app.get("/tiles/:version/tiles/:z/:x/:y.pbf", function(req, res) {
const { z, x, y } = req.params;
new MBTiles(path.join(__dirname, "tiles.mbtiles"), function(err, mbtiles) {
new MBTiles(path.join(__dirname, "tiles", "tiles.mbtiles"), function(
err,
mbtiles
) {
if (err) {
res.header("Content-Type", "text/plain");
res.status(500).send(`Tile error: ${err}`);
Expand All @@ -33,7 +36,7 @@ const themeHandler = function(req, res) {
if (!theme.endsWith(".json")) {
theme = theme + ".json";
}
const filePath = path.join(__dirname, `themes/${theme}`);
const filePath = path.join(__dirname, "themes", theme);
fs.readFile(filePath, "utf8", function(err, file) {
if (err) {
res.status(500);
Expand All @@ -57,7 +60,9 @@ app.get("/tiles/styles/:version/:theme/sprite.json", function(req, res) {
});

app.get("/tiles/styles/:version/:theme/sprite.png", function(req, res) {
const reader = fs.createReadStream(path.join(__dirname, "themes/sprite.png"));
const reader = fs.createReadStream(
path.join(__dirname, "themes", "sprite.png")
);
reader.on("open", () => {
res.header("Content-Type", "image/png");
reader.pipe(res);
Expand Down
2 changes: 1 addition & 1 deletion index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test("map tiles are served appropriately out of the mbtiles archive", async t =>
// Promise-based helper to read a tile out of an mbtiles archive
function getTile(z, x, y) {
return new Promise((resolve, reject) => {
new MBTiles("./tiles.mbtiles", (err, mbtiles) => {
new MBTiles("./tiles/tiles.mbtiles", (err, mbtiles) => {
if (err) {
reject(500);
} else {
Expand Down

0 comments on commit 6d94db7

Please sign in to comment.