Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Trigger Netlify Build
on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
name: 'Deploy to Netlify'
steps:
- uses: actions/checkout@v3
- uses: jsmrcaga/action-netlify-deploy@v2.4.0
with:
NETLIFY_AUTH_TOKEN: ${{ secrets.NEW_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.MY_SITE_ID }}
NETLIFY_DEPLOY_TO_PROD: true
build_directory: dist/hello-ci-cd/browser
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ testem.log
# System files
.DS_Store
Thumbs.db
.env
enviroment.ts
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# https://randomredditmeme.netlify.app/

# Angular CI/CD

## Learning objectives
Expand Down
4 changes: 4 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build]
command = "npm run build"
publish = "dist/hello-ci-cd/browser"
functions = "netlify/functions"
36 changes: 36 additions & 0 deletions netlify/functions/get-meme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Handler } from '@netlify/functions'
import fetch from 'node-fetch'

const handler: Handler = async () => {
const apiKey = process.env['APILEAGUE_API_KEY']
const apiUrl = 'https://api.apileague.com/retrieve-random-meme'

try {
const response = await fetch(apiUrl, {
headers: {
'x-api-key': apiKey ?? ''
}
})

if (!response.ok) {
return {
statusCode: response.status,
body: `API error: ${response.statusText}`
}
}

const data = await response.json()

return {
statusCode: 200,
body: JSON.stringify(data)
}
} catch (error: any) {
return {
statusCode: 500,
body: `Server error: ${error.message}`
}
}
}

export { handler }
Loading