tarea german santiago
This commit is contained in:
parent
b5628e1a35
commit
44988f110f
13
Clase 1/tareaGermanSantiago/Dockerfile
Normal file
13
Clase 1/tareaGermanSantiago/Dockerfile
Normal file
@ -0,0 +1,13 @@
|
||||
FROM node:18
|
||||
|
||||
#creamos un directorio para codigo js
|
||||
RUN mkdir -p /home/app
|
||||
|
||||
#copiamos codigo a directorio
|
||||
COPY . /home/app
|
||||
|
||||
#exponemos puesto
|
||||
EXPOSE 3000
|
||||
|
||||
# ejecutamos comando para levantar servicio node
|
||||
CMD ["node", "/home/app/index.js"]
|
19
Clase 1/tareaGermanSantiago/docker-compose.yml
Normal file
19
Clase 1/tareaGermanSantiago/docker-compose.yml
Normal file
@ -0,0 +1,19 @@
|
||||
version: "1.0"
|
||||
services:
|
||||
aplicacion:
|
||||
build: .
|
||||
ports:
|
||||
- "3000:3000"
|
||||
links:
|
||||
- bdatos
|
||||
bdatos:
|
||||
image: mongo
|
||||
ports:
|
||||
- "27017:27017"
|
||||
environment:
|
||||
- MONGO_INITDB_ROOT_USERNAME=santiage
|
||||
- MONGO_INITDB_ROOT_PASSWORD=santiagepass
|
||||
|
||||
|
||||
|
||||
|
25
Clase 1/tareaGermanSantiago/index.js
Normal file
25
Clase 1/tareaGermanSantiago/index.js
Normal file
@ -0,0 +1,25 @@
|
||||
import express from 'express'
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
const Animal = mongoose.model('Animal', new mongoose.Schema({
|
||||
tipo: String,
|
||||
estado: String,
|
||||
}))
|
||||
|
||||
const app = express()
|
||||
|
||||
mongoose.connect('mongodb://santiage:santiagepass@bdatos:27017/miapp?authSource=admin')
|
||||
|
||||
app.get('/', async (_req, res) => {
|
||||
console.log('listando... base de datos...')
|
||||
const animales = await Animal.find();
|
||||
return res.send(animales)
|
||||
})
|
||||
app.get('/crear/:pTipo', async (_req, res) => {
|
||||
|
||||
console.log('creando...')
|
||||
await Animal.create({ tipo: _req.params.pTipo, estado: 'estado' })
|
||||
return res.send('ok')
|
||||
})
|
||||
|
||||
app.listen(3000, () => console.log('escuchando ...'))
|
1514
Clase 1/tareaGermanSantiago/package-lock.json
generated
Normal file
1514
Clase 1/tareaGermanSantiago/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
16
Clase 1/tareaGermanSantiago/package.json
Normal file
16
Clase 1/tareaGermanSantiago/package.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "mongoapp",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"express": "^4.18.1",
|
||||
"mongoose": "6.4.1"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user