Skip to content

Commit

Permalink
fix(tiler): dev start script
Browse files Browse the repository at this point in the history
  • Loading branch information
bartolkaruza committed Oct 23, 2019
1 parent 0a0f524 commit 40e3c56
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 53 deletions.
91 changes: 44 additions & 47 deletions example/exampleServer.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,56 @@
const express = require('express');
const uuid = require('uuid');
require('../js/server');

const port = 80;

const table = 'public.stations';
const geometry = 'wkb_geometry';
const maxZoomLevel = 12;

const supertiler = require('../js/server');
const supertiler = require('../dist');
supertiler({
maxZoomLevel,
geometry,
table,
resolution: 512, // Mapbox default, try 256 if you are unsure what your mapping front-end library uses
attributeMap: { status: 'status' },
filterQuery: filters => {
const whereStatements = [];
if (filters.status) {
whereStatements.push(`status = ${filters.status}`);
}
return whereStatements.join(' AND ')
},
additionalProperties: ['status', 'speed'],
maxZoomLevel,
geometry,
table,
resolution: 512, // Mapbox default, try 256 if you are unsure what your mapping front-end library uses
attributeMap: { status: 'status' },
filterQuery: filters => {
const whereStatements = [];
if (filters.status) {
whereStatements.push(`status = ${filters.status}`);
}
return whereStatements.join(' AND ');
},
additionalProperties: ['status', 'speed'],
}).then(server => {
const app = express();
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', 'http://localhost:3000');
next();
});
app.get('/health', (req, res) => {
res.status(200).send('OK');
});
app.get('/stations/:z/:x/:y/tile.mvt', (req, res) => {
req.id = uuid.v4();
console.time(req.id);
server({
z: req.params.z,
x: req.params.x,
y: req.params.y,
id: req.id,
})
.then(result => {
res.setHeader('Content-Type', 'application/x-protobuf');
res.setHeader('Content-Encoding', 'gzip');
console.time('send' + req.id);
res.status(200).send(result);
console.timeEnd('send' + req.id);
console.timeEnd(req.id);
})
.catch(e => {
res.status(400).send('Oops');
});
});
app.listen(port, () =>
console.log(`Example app listening on port ${port}!`)
);
const app = express();
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', 'http://localhost:3000');
next();
});
app.get('/health', (req, res) => {
res.status(200).send('OK');
});
app.get('/stations/:z/:x/:y/tile.mvt', (req, res) => {
req.id = uuid.v4();
console.time(req.id);
server({
z: req.params.z,
x: req.params.x,
y: req.params.y,
id: req.id,
})
.then(result => {
res.setHeader('Content-Type', 'application/x-protobuf');
res.setHeader('Content-Encoding', 'gzip');
console.time('send' + req.id);
res.status(200).send(result);
console.timeEnd('send' + req.id);
console.timeEnd(req.id);
})
.catch(e => {
res.status(400).send('Oops');
});
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"name": "super-tiler",
"version": "1.0.0",
"description": "MVT map tiling server with built-in clustering and filtering",
"main": "index.js",
"main": "dist/index.js",
"repository": "https://github.com/chargetrip/super-tiler",
"author": "Bartol Karuza",
"license": "MIT",
"private": true,
"scripts": {
"start": "rollup --config rollup.config.js js/server.ts",
"start": "rollup --config rollup.config.js && node example/exampleServer.js",
"babel": "babel js --out-dir dist --extensions \".ts\" --exclude \"**/__test__/*\"",
"test": "jest"
},
Expand Down
13 changes: 9 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,31 @@ import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';

export default {
input: './example/exampleServer.js',
input: './js/server.ts',
output: {
file: 'dist/index.js',
format: 'cjs',
},
plugins: [
resolve({
extensions: ['.js', '.ts'],
preferBuiltins: true
preferBuiltins: true,
}),
json(),
commonjs({
include: 'node_modules/**',
extensions: ['.js'],
ignore: ['pg-native' , './native']
ignore: ['pg-native', './native'],
}),
babel({
exclude: ['node_modules/**', '**/__test__/**'],
extensions: ['.js', '.ts'],
}),
run(),
run({
env: {
ENV_FILE: '.development.env',
},
execArgv: ['-r', 'source-map-support/register'],
}),
],
};

0 comments on commit 40e3c56

Please sign in to comment.