Skip to content

Commit

Permalink
geo location example
Browse files Browse the repository at this point in the history
  • Loading branch information
gojko committed Dec 23, 2016
1 parent 7e2b21a commit fbb96a6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* [GitHub Repository Labels](github-repo-labels) – a simple image server, shows how to map URL path components to arguments, how to customise response types and how to connect to third party REST APIs
* [Using AWS Mobile Analytics for server-side events](aws-mobile-analytics) – log events into AWS Mobile Analytics for easy internal telemetry
* [Custom Authorizers](custom-authorizers) – a simple example of how to set up custom authorizers in API Gateway
* [Geo location](api-gw-geolocatio) – shows how to retrieve the country where your users originated the request

## Proxy API

Expand Down
11 changes: 11 additions & 0 deletions api-gw-geolocation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Geolocation using API Gateway

API Gateway requests go through CloudFront, and they will contain a few useful analytic headers, including the geo-location country
where the request originated. This is a simple example that shows how to read out the country header and use it in your API.

## Get started

* run `npm init` to install the dependencies
* run `npm run create` to deploy this project to AWS
* grab the URL printed as the result, and GET it using CURL or paste into a browser

13 changes: 13 additions & 0 deletions api-gw-geolocation/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*global module, require */
var API = require('claudia-api-builder'),
api = new API();

api.get('/', function (request) {
'use strict';
return {
IP: request.context.sourceIp,
Country: request.headers['CloudFront-Viewer-Country']
};
});

module.exports = api;
19 changes: 19 additions & 0 deletions api-gw-geolocation/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "api-gw-geolocation",
"version": "1.0.0",
"description": "A simple demonstration of built-in geolocation service with API Gateway",
"main": "index.js",
"scripts": {
"create": "claudia create --region us-east-1 --api-module api",
"update": "claudia update"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"claudia-api-builder": "^2.3.1"
},
"devDependencies": {
"claudia": "^2.5.0"
}
}

0 comments on commit fbb96a6

Please sign in to comment.