Skip to content

Commit

Permalink
Cambios para despliegue
Browse files Browse the repository at this point in the history
  • Loading branch information
UO264802 committed May 5, 2022
1 parent f1549f4 commit 559e2a1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/asw2122.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
password: ${{ secrets.DOCKER_PUSH_TOKEN }}
registry: ghcr.io
workdir: webapp
buildargs: API_URI
docker-push-restapi:
name: Push restapi Docker Image to GitHub Packages
runs-on: ubuntu-latest
Expand All @@ -85,7 +86,7 @@ jobs:
user: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
command: |
wget https://github.com/Arquisoft/dede_es6b/blob/develop/docker-compose-deploy.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/Arquisoft/dede_es6b/master/docker-compose-deploy.yml -O docker-compose.yml
docker-compose stop
docker-compose rm -f
docker-compose pull
Expand Down
8 changes: 4 additions & 4 deletions restapi/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import api from "./api"
const app: Application = express();
const port: number = 5000;

const options: cors.CorsOptions = {
origin: ['http://localhost:3000']
};
// const options: cors.CorsOptions = {
// origin: ['http://localhost:3000']
// };

let bd = require('./utils/connectDB')

const metricsMiddleware:RequestHandler = promBundle({includeMethod: true});
app.use(metricsMiddleware);

app.use(cors(options));
app.use(cors());
app.use(bp.json());
app.use(express.json());

Expand Down
36 changes: 8 additions & 28 deletions webapp/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,8 @@ import {Product, Pedido, PaymentType} from '../shared/shareddtypes';
import {ShipmentData, User} from '../shared/shareddtypes';


export async function addUser(user:User):Promise<boolean>{
const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000/api'
let response = await fetch(apiEndPoint+'/users/add', {
method: 'POST',
headers: {'Content-Type':'application/json'},
body: JSON.stringify({'name':user.name, 'email':user.email})
});
if (response.status===200)
return true;
else
return false;
}

export async function getUsers():Promise<User[]>{
const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000/api'
let response = await fetch(apiEndPoint+'/users/list');
//The objects returned by the api are directly convertible to User objects
return response.json()
}

export async function addOrder(cartProducts:Product[], price:number, url:string, user_id:string|undefined){
const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000'
const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000/api'
let response = await fetch(apiEndPoint+'/orders/add', {
method: 'POST',
headers: {'Content-Type':'application/json'},
Expand All @@ -34,7 +14,7 @@ export async function addOrder(cartProducts:Product[], price:number, url:string,
}

export async function getOrdersByUser(user_id:string|undefined){
const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000'
const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000/api'
let response = await fetch(apiEndPoint + "/orders/" + user_id);
return response.json();

Expand All @@ -43,21 +23,21 @@ export async function getOrdersByUser(user_id:string|undefined){

//Devuelve los productos de la base de datos
export async function getProducts():Promise<Product[]>{
const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000'
const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000/api'
let response = await fetch(apiEndPoint+'/products/list');
//The objects returned by the api are directly convertible to Product objects
return response.json()
}

export async function getProductsByCategory(category: string): Promise<Product[]>{
const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000'
const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000/api'
let response = await fetch(apiEndPoint + "/products/" + category);
return response.json();
}

//Producto por código
export async function getProductByCode(code: string): Promise<Product[]>{
const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000'
const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000/api'
let response = await fetch(apiEndPoint + "/products/find/" + code);
return response.json();
}
Expand Down Expand Up @@ -94,7 +74,7 @@ export async function createTransaction(rate:string):Promise<JSON>{


export async function getPedidos(): Promise<Pedido[]> {
const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000'
const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/api'
let response = await fetch(apiEndPoint + '/orders/list');
//The objects returned by the api are directly convertible to User objects
console.log(response);
Expand All @@ -103,14 +83,14 @@ export async function getPedidos(): Promise<Pedido[]> {


export async function getPedidosByUser(user_id:string):Promise<Pedido[]>{
const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000'
const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000/api'
let response = await fetch(apiEndPoint+'/orders/'+user_id);
//The objects returned by the api are directly convertible to Product objects
return response.json()
}

export async function getPaymentsType():Promise<PaymentType[]>{
const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000'
const apiEndPoint= process.env.REACT_APP_API_URI || 'http://localhost:5000/api'
let response = await fetch(apiEndPoint+'/payments');
//The objects returned by the api are directly convertible to Product objects
return response.json()
Expand Down

0 comments on commit 559e2a1

Please sign in to comment.