-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
103 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules/ | ||
keys.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,18 +3,43 @@ const limitedMap = require("limited-map"); | |
const query = require("micro-query"); | ||
const cors = require("micro-cors")(); | ||
const { FileTileSet, S3TileSet } = require("./tileset"); | ||
//const hat = require('hat'); | ||
const crypto = require('crypto'); | ||
const keys = require('./keys.js'); | ||
|
||
const cacheSize = process.env.TILE_SET_CACHE || 128; | ||
const tileFolder = process.env.TILE_SET_PATH || __dirname; | ||
const maxPostSize = process.env.MAX_POST_SIZE || "500kb"; | ||
const maxPostSize = process.env.MAX_POST_SIZE || "1000kb"; | ||
const maxParallelProcessing = 500; | ||
|
||
// var rack = hat.rack(); | ||
// var key = rack(); | ||
// var key = 'your-key-goes-here'; | ||
// const shasum = crypto.createHash('sha256'); | ||
// shasum.update(key); | ||
// console.log(shasum.digest('hex')); | ||
|
||
const tiles = tileFolder.startsWith("s3://") | ||
? new S3TileSet({ cacheSize }) | ||
: new FileTileSet(tileFolder, { cacheSize }); | ||
|
||
async function handlePOST(req, res) { | ||
const payload = await json(req, { limit: maxPostSize }); | ||
const reqQuery = query(req); | ||
const apiKey = reqQuery.key; | ||
|
||
if (!apiKey) { | ||
return send(res, 400, { | ||
error: apiMessage('Missing'), | ||
}); | ||
} | ||
|
||
if (verifyKey(apiKey) < 0) { | ||
return send(res, 400, { | ||
error: apiMessage('Invalid'), | ||
}); | ||
} | ||
|
||
if ( | ||
!payload || | ||
!Array.isArray(payload) || | ||
|
@@ -36,6 +61,19 @@ async function handlePOST(req, res) { | |
|
||
async function handleGET(req, res) { | ||
const reqQuery = query(req); | ||
const apiKey = reqQuery.key; | ||
if (!apiKey) { | ||
return send(res, 400, { | ||
error: apiMessage('Missing'), | ||
}); | ||
} | ||
|
||
if (verifyKey(apiKey) < 0) { | ||
return send(res, 400, { | ||
error: apiMessage('Invalid'), | ||
}); | ||
} | ||
|
||
const lat = parseFloat(reqQuery.lat); | ||
const lng = parseFloat(reqQuery.lng); | ||
if (lat == null || !Number.isFinite(lat)) { | ||
|
@@ -76,4 +114,17 @@ async function handler(req, res) { | |
} | ||
} | ||
|
||
function verifyKey(key) { | ||
const shasum = crypto.createHash('sha256'); | ||
shasum.update(key); | ||
const allKeys = keys.get(); | ||
const digest = shasum.digest('hex'); | ||
return allKeys.indexOf(digest); | ||
} | ||
|
||
function apiMessage(wrong) { | ||
return wrong + ' API key. Please email Téo or Julien at [email protected] or [email protected].' | ||
} | ||
|
||
|
||
module.exports = cors(handler); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
0 info it worked if it ends with ok | ||
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ] | ||
2 info using [email protected] | ||
3 info using [email protected] | ||
4 verbose run-script [ 'prestart', 'start', 'poststart' ] | ||
5 info lifecycle [email protected]~prestart: [email protected] | ||
6 silly lifecycle [email protected]~prestart: no script for prestart, continuing | ||
7 info lifecycle [email protected]~start: [email protected] | ||
8 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true | ||
9 verbose lifecycle [email protected]~start: PATH: /usr/share/npm/bin/node-gyp-bin:/home/julien/elevation-service/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin | ||
10 verbose lifecycle [email protected]~start: CWD: /home/julien/elevation-service | ||
11 silly lifecycle [email protected]~start: Args: [ '-c', 'micro -l tcp://0.0.0.0:4000 index.js' ] | ||
12 silly lifecycle [email protected]~start: Returned: code: 1 signal: null | ||
13 info lifecycle [email protected]~start: Failed to exec start script | ||
14 verbose stack Error: [email protected] start: `micro -l tcp://0.0.0.0:4000 index.js` | ||
14 verbose stack Exit status 1 | ||
14 verbose stack at EventEmitter.<anonymous> (/usr/share/npm/lib/utils/lifecycle.js:232:16) | ||
14 verbose stack at emitTwo (events.js:126:13) | ||
14 verbose stack at EventEmitter.emit (events.js:214:7) | ||
14 verbose stack at ChildProcess.<anonymous> (/usr/share/npm/lib/utils/spawn.js:24:14) | ||
14 verbose stack at emitTwo (events.js:126:13) | ||
14 verbose stack at ChildProcess.emit (events.js:214:7) | ||
14 verbose stack at maybeClose (internal/child_process.js:925:16) | ||
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5) | ||
15 verbose pkgid [email protected] | ||
16 verbose cwd /home/julien/elevation-service | ||
17 error Linux 4.15.0-70-generic | ||
18 error argv "/usr/bin/node" "/usr/bin/npm" "start" | ||
19 error node v8.10.0 | ||
20 error npm v3.5.2 | ||
21 error code ELIFECYCLE | ||
22 error [email protected] start: `micro -l tcp://0.0.0.0:4000 index.js` | ||
22 error Exit status 1 | ||
23 error Failed at the [email protected] start script 'micro -l tcp://0.0.0.0:4000 index.js'. | ||
23 error Make sure you have the latest version of node.js and npm installed. | ||
23 error If you do, this is most likely a problem with the elevation-service package, | ||
23 error not with npm itself. | ||
23 error Tell the author that this fails on your system: | ||
23 error micro -l tcp://0.0.0.0:4000 index.js | ||
23 error You can get information on how to open an issue for this project with: | ||
23 error npm bugs elevation-service | ||
23 error Or if that isn't available, you can get their info via: | ||
23 error npm owner ls elevation-service | ||
23 error There is likely additional logging output above. | ||
24 verbose exit [ 1, true ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,14 @@ | |
"version": "0.0.1", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "micro index.js", | ||
"start": "micro -l tcp://0.0.0.0:4000 index.js", | ||
"test": "node test/test.js", | ||
"pretty": "prettier --write *.js test/*.js" | ||
}, | ||
"author": "Norman Rzepka <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"hat": "0.0.3", | ||
"limited-map": "^0.0.1", | ||
"lru-memoize": "^1.0.2", | ||
"micro": "^9.3.2", | ||
|