OSRM API NODEJS
OSRM implementation for API. Opened cause no benefit from the previous company to the coder!
-
UBUNTU Server
-
NodeJS ^v10
-
Global
node-pre-gyp
,node-gyp
,nodemon
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update -y
sudo apt install build-essential git cmake pkg-config \
libbz2-dev libxml2-dev libzip-dev libboost-all-dev \
lua5.2 liblua5.2-dev libtbb-dev libstdc++-5-dev
see https://github.com/Project-OSRM/osrm-backend
Follow OSRM data storage README.md
- osrm@^5.22.0
- expresss@^4.1
- maxmind@^4.1.0
- yaml@^1.7.2
- express-group-routes@^1.1.0
- GEOIP : https://db-ip.com/db/lite.php
- OSRM : https://github.com/Project-OSRM/
- OSM : https://openstreetmap.org
- GEO JSON - see world.geo.json
- PORT :
5050
to5059
Running osrm-server.sh
as daemon background service :
setsid ./osrm-server.sh >/dev/null 2>&1 < /dev/null &
add header X-Auth-Token
with with declared token to get access
# MAKE SURE INSTALL MOD UPSTREAM & FAIR
# FILE $domain.vhost.conf
# NGINX NODE UPSTREAM ADD MAX FAILS 3 & FAILED TIMEDOUT 30 SECONDS
upstream node_proxy_osrm {
least_conn;
server 127.0.0.1:5050 max_fails=3 fail_timeout=30s;
server 127.0.0.1:5051 max_fails=3 fail_timeout=30s;
server 127.0.0.1:5052 max_fails=3 fail_timeout=30s;
server 127.0.0.1:5053 max_fails=3 fail_timeout=30s;
server 127.0.0.1:5054 max_fails=3 fail_timeout=30s;
server 127.0.0.1:5055 max_fails=3 fail_timeout=30s;
server 127.0.0.1:5056 max_fails=3 fail_timeout=30s;
server 127.0.0.1:5057 max_fails=3 fail_timeout=30s;
server 127.0.0.1:5058 max_fails=3 fail_timeout=30s;
server 127.0.0.1:5059 max_fails=3 fail_timeout=30s;
fair;
}
server {
listen 80;
# listen 443 ssl http2;
# ssl_certificate /etc/letsencrypt/live/$domain/fullchain.pem;
# ssl_certificate_key /etc/letsencrypt/live/$domain/privkey.pem;
# ROOT PATH JUST TO TRY FILES
root /home/$user/host/$domain/public;
# SERVER NAME / DOMAIN
server_name $domain www.$domain;
# SET DEFAULT MIME TYPE
default_type text/html;
# ADD PROXY HEADER
proxy_set_header X-Forwarded-For $remote_addr;
# ADD REAL HOST
proxy_set_header Host $http_host;
# ------------------------------------------------------------
# ERROR HANDLER
# ------------------------------------------------------------
# INDEX (NOT USED) NO INDEX TO MAKE SURE HANDLE BY NGINX
# index '#';
# ERROR HANDLER
location = '/#401' {
default_type application/json;
add_header Content-Type application/json;
return 401 '{
"message": "401 Unauthorized"
}';
}
location = '/#404' {
default_type application/json;
add_header Content-Type application/json;
return 404 '{
"message": "404 Not Found"
}';
}
location = '/#403' {
default_type application/json;
add_header Content-Type application/json;
return 403 '{
"message": "403 Forbidden"
}';
}
location = '/#500' {
default_type application/json;
add_header Content-Type application/json;
return 500 '{
"message": "500 Internal Server Error"
}';
}
location = '/#502' {
default_type application/json;
add_header Content-Type application/json;
return 502 '{
"message": "502 Bad Gateway"
}';
}
location = '/#504' {
default_type application/json;
add_header Content-Type application/json;
return 504 '{
"message": "504 Gateway Timeout"
}';
}
# HANDLE ERROR
error_page 401 '/#401';
error_page 404 '/#404';
error_page 403 '/#403';
error_page 500 '/#500';
error_page 502 '/#502';
error_page 504 '/#504';
# ------------------------------------------------------------
# LOCATIONS
# ------------------------------------------------------------
location @proxy {
proxy_pass http://node_proxy_osrm;
}
# HANDLE LOCATION
# use try_files $uri @proxy; -> to prevent accessing directory as allowed url index
location / {
try_files $uri $uri/ @proxy;
}
}
Github : @ArrayIterator