diff --git a/.gitignore b/.gitignore index 80d79ed..1787a05 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ yarn-error.log* docs/build restapi/.env +webapp/lomapes2c.eastus.cloudapp.azure.com.key +webapp/lomapes2c.eastus.cloudapp.azure.com.crt diff --git a/docker-compose-deploy.yml b/docker-compose-deploy.yml index 1a03c94..e37ceca 100644 --- a/docker-compose-deploy.yml +++ b/docker-compose-deploy.yml @@ -7,6 +7,6 @@ services: webapp: image: ghcr.io/arquisoft/lomap_es2c/webapp:latest ports: - - "3000:3000" + - "443:443" depends_on: - restapi diff --git a/docker-compose.yml b/docker-compose.yml index 8089399..e6b1aeb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: webapp: build: ./webapp ports: - - "3000:3000" + - "443:443" depends_on: - restapi prometheus: diff --git a/restapi/server.ts b/restapi/server.ts index 94e4eac..9d4a2c6 100644 --- a/restapi/server.ts +++ b/restapi/server.ts @@ -9,11 +9,13 @@ const mongoose = require('mongoose'); const app: Application = express(); -const port: number = 5000; +const port: number = Number.parseInt(`${process.env.PORT}`) || 5000; const metricsMiddleware: RequestHandler = promBundle({ includeMethod: true }); app.use(metricsMiddleware); +app.disable("x-powered-by"); + mongoose.connect('mongodb+srv://admin:admin@prueba.bwoulkv.mongodb.net/?retryWrites=true&w=majority', { useNewUrlParser: true, @@ -27,6 +29,11 @@ app.use(bp.json()); app.use("/api", api) +app.use(cors({ + origin: ['https://lomapes2c.eastus.cloudapp.azure.com/' , 'http://localhost:3000'], + credentials:true +})); + app.listen(port, (): void => { console.log('Restapi listening on ' + port); }).on("error", (error: Error) => { diff --git a/webapp/server.ts b/webapp/server.ts index 6cf2865..06c84ca 100644 --- a/webapp/server.ts +++ b/webapp/server.ts @@ -1,10 +1,17 @@ import express, { Application } from 'express'; +import https from 'https'; +import fs from 'fs'; + const path = require('path'); const publicPath = path.join(__dirname, '.', 'build'); var app: Application = express(); -const port: number = 3000; + +const HTTPS_PORT = 443; +const HTTP_PORT = 3000; + + app.use(express.static("build")); @@ -16,10 +23,33 @@ app.get('*', (req, res) => { }; }); -app - .listen(port, (): void => { - console.log("Webapp started on port " + port); - }) - .on("error", (error: Error) => { - console.error("Error occured: " + error.message); - }); +app.use((req, res, next) => { + if (req.secure) { + next(); + } else { + res.redirect(`https://${req.headers.host}${req.url}`); + } +}); + + +if (process.env.NODE_ENV === "production") +{ + const options = { + cert: fs.readFileSync('/etc/ssl/certs/lomapes2c.eastus.cloudapp.azure.com.crt'), + key: fs.readFileSync('/etc/ssl/private/lomapes2c.eastus.cloudapp.azure.com.key'), + }; + + https.createServer(options, app).listen(HTTPS_PORT, () => { + console.log(`Webapp started on port ${HTTPS_PORT}`); + }).on("error", (error: Error) => { + console.error("Error occured: " + error.message); + }); + +} else { + app.listen(HTTP_PORT, () => { + console.log(`Webapp started on port ${HTTP_PORT} (development)`); + }).on("error", (error: Error) => { + console.error("Error occured: " + error.message); + }); +} + diff --git a/webapp/src/api/api.ts b/webapp/src/api/api.ts index 9ffa577..62ead2d 100644 --- a/webapp/src/api/api.ts +++ b/webapp/src/api/api.ts @@ -34,6 +34,7 @@ export async function signup(user: User): Promise { export async function login(user: User): Promise { const apiEndPoint = process.env.REACT_APP_API_URI || 'http://localhost:5000/api' + console.log(apiEndPoint) let response = await fetch(apiEndPoint + '/sesionmanager/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, diff --git a/webapp/src/components/mainComponents/ImgCarrusel.tsx b/webapp/src/components/mainComponents/ImgCarrusel.tsx index 8e12448..c877d0f 100644 --- a/webapp/src/components/mainComponents/ImgCarrusel.tsx +++ b/webapp/src/components/mainComponents/ImgCarrusel.tsx @@ -46,15 +46,15 @@ export default function StandardImageList() { const itemData = [ { - img: '1.png', + img: '/1.png', title: 'Crea tus propios mapas', }, { - img: '2.png', + img: '/2.png', title: 'Guarda tus lugares favoritos', }, { - img: '4.png', + img: '/4.png', title: 'Ve los mapas de tus amigos', } ]; \ No newline at end of file diff --git a/webapp/src/components/userIdentification/podLogin/Pod.tsx b/webapp/src/components/userIdentification/podLogin/Pod.tsx index ecd76c2..866a238 100644 --- a/webapp/src/components/userIdentification/podLogin/Pod.tsx +++ b/webapp/src/components/userIdentification/podLogin/Pod.tsx @@ -88,8 +88,8 @@ export default function PodLogin() { {"Logo {option.name} @@ -108,7 +108,7 @@ export default function PodLogin() { {"Logo