-
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.
Adição do projeto de Web API com Serverless da Ana Neri no Youtube
- Loading branch information
Showing
9 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
Youtube/AnaNeri_Criando_Web_API_Serverless_em_minutos/my-service/.gitignore
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,6 @@ | ||
# package directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Serverless directories | ||
.serverless |
23 changes: 23 additions & 0 deletions
23
Youtube/AnaNeri_Criando_Web_API_Serverless_em_minutos/my-service/Dockerfile
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,23 @@ | ||
FROM node:16-alpine | ||
|
||
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app | ||
|
||
WORKDIR /home/node/app | ||
|
||
COPY --chown=node:node package*.json ./ | ||
|
||
USER node | ||
|
||
RUN ls -la /home/node/app | ||
|
||
RUN npm install serverless | ||
|
||
RUN npm install serverless-offline | ||
|
||
RUN npm install mongodb | ||
|
||
COPY --chown=node:node . . | ||
|
||
EXPOSE 3000 | ||
|
||
CMD ["npm", "run", "start"] |
1 change: 1 addition & 0 deletions
1
Youtube/AnaNeri_Criando_Web_API_Serverless_em_minutos/my-service/data/mongod.lock
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 @@ | ||
8 |
25 changes: 25 additions & 0 deletions
25
Youtube/AnaNeri_Criando_Web_API_Serverless_em_minutos/my-service/docker-compose.yaml
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,25 @@ | ||
version: '3' | ||
services: | ||
app: | ||
build: . | ||
volumes: | ||
- .:/app | ||
networks: | ||
- mongodb_network | ||
ports: | ||
- 3000:3000 | ||
mongodb: | ||
container_name: mongodb | ||
image: mongodb/mongodb-community-server:6.0-ubi8 | ||
volumes: | ||
- mongodata:/data/db | ||
networks: | ||
- mongodb_network | ||
ports: | ||
- 27017:27017 | ||
networks: | ||
mongodb_network: | ||
driver: bridge | ||
volumes: | ||
mongodata: | ||
driver: local |
11 changes: 11 additions & 0 deletions
11
Youtube/AnaNeri_Criando_Web_API_Serverless_em_minutos/my-service/info.txt
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,11 @@ | ||
https://stackoverflow.com/questions/44781889/permission-error-with-mongo-when-running-docker/73565165#73565165 | ||
|
||
https://stackoverflow.com/questions/49937772/docker-volume-must-be-a-mapping-not-a-string | ||
|
||
localhost:3000/dev/data | ||
|
||
https://www.mongodb.com/community/forums/t/asp-net-mongo-db-system-timeoutexception-a-timeout-occurred-after-30000ms-in-docker-compose/180483 | ||
|
||
https://stackoverflow.com/questions/74165616/timeout-mongodb-with-docker | ||
|
||
Link do video deste projeto no youtube: https://www.youtube.com/watch?v=3A8APu9FiSI |
13 changes: 13 additions & 0 deletions
13
Youtube/AnaNeri_Criando_Web_API_Serverless_em_minutos/my-service/package.json
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,13 @@ | ||
{ | ||
"name": "my-service", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "handler.js", | ||
"scripts": { | ||
"start": "npx serverless offline start --host 0.0.0.0", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
8 changes: 8 additions & 0 deletions
8
Youtube/AnaNeri_Criando_Web_API_Serverless_em_minutos/my-service/scripts.txt
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,8 @@ | ||
serverless create --template aws-nodejs --path my-service | ||
npm init --y | ||
npm install -g serverless serverless-offline mongodb | ||
npm run start | ||
docker-compose up --build | ||
docker system prune -a --volumes | ||
|
||
docker system prune -a --volumes -f; clear; docker-compose up --build |
18 changes: 18 additions & 0 deletions
18
Youtube/AnaNeri_Criando_Web_API_Serverless_em_minutos/my-service/serverless.yml
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,18 @@ | ||
service: my-service | ||
frameworkVersion: "3" | ||
|
||
plugins: | ||
- serverless-offline | ||
|
||
provider: | ||
name: aws | ||
runtime: nodejs18.x | ||
timeout: 30 | ||
|
||
functions: | ||
putData: | ||
handler: src/handler.putData | ||
events: | ||
- http: | ||
path: data | ||
method: put |
20 changes: 20 additions & 0 deletions
20
Youtube/AnaNeri_Criando_Web_API_Serverless_em_minutos/my-service/src/handler.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
const MongoClient = require('mongodb').MongoClient; | ||
|
||
module.exports.putData = async(event) => { | ||
const client = new MongoClient('mongodb://mongodb:27017', {useUnifiedTopology: true}); | ||
await client.connect(); | ||
|
||
const db = client.db('mydb'); | ||
const collection = db.collection('mycollection'); | ||
|
||
const data = JSON.parse(event.body); | ||
await collection.insertOne(data); | ||
|
||
await client.close(); | ||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify({message: 'VEIO AQUIIIIIIII'}) | ||
}; | ||
}; |