Skip to content

Commit

Permalink
Country
Browse files Browse the repository at this point in the history
  • Loading branch information
biilmann committed Sep 12, 2021
1 parent ea59122 commit bdea4c8
Show file tree
Hide file tree
Showing 8 changed files with 241 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -16,3 +16,6 @@ yarn-error.log*

# macOS-specific files
.DS_Store

# Local Netlify folder
.netlify
2 changes: 1 addition & 1 deletion astro.config.mjs
Expand Up @@ -12,5 +12,5 @@ export default {
// port: 3000, // The port to run the dev server on.
// tailwindConfig: '', // Path to tailwind.config.js if used, e.g. './tailwind.config.js'
},
renderers: [],
renderers: ['@astrojs/renderer-svelte'],
};
21 changes: 21 additions & 0 deletions netlify.toml
@@ -0,0 +1,21 @@
# example netlify.toml
[build]
command = "astro build"
functions = "netlify/functions"
publish = "dist"

## Uncomment to use this redirect for Single Page Applications like create-react-app.
## Not needed for static site generators.
#[[redirects]]
# from = "/*"
# to = "/index.html"
# status = 200

## (optional) Settings for Netlify Dev
## https://github.com/netlify/cli/blob/main/docs/netlify-dev.md#project-detection
#[dev]
# command = "yarn start" # Command to start your dev server
# port = 3000 # Port that the dev server will be listening on
# publish = "dist" # Folder with the static content for _redirect file

## more info on configuring this file: https://www.netlify.com/docs/netlify-toml-reference/
21 changes: 21 additions & 0 deletions netlify/functions/country/country.ts
@@ -0,0 +1,21 @@
import { Handler } from '@netlify/functions'
import { gql, request } from 'graphql-request'

const endpoint = 'https://countries.trevorblades.com/'

export const handler: Handler = async (event, context) => {
const country = event.headers['x-country'] || 'US'
const query = gql`{
country(code: "${country}") {
name, emoji
}
}`

const result = await request(endpoint, query)

return {
statusCode: 200,
body: JSON.stringify(result),
headers: {"Content-Type": "application/json"}
}
}

0 comments on commit bdea4c8

Please sign in to comment.