Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
UO281801 committed May 2, 2023
1 parent d5d37fc commit a3cb07d
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 144 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lomap_en1a.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
env:
API_URI: https://${{ secrets.DEPLOY_HOST }}:5000/api
API_URI: http://${{ secrets.DEPLOY_HOST }}:5000/api
with:
name: arquisoft/lomap_en1a/webapp
username: ${{ github.actor }}
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
user: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
command: |
wget https://raw.githubusercontent.com/arquisoft/lomap_en1a/UI-Vanesa2/docker-compose-deploy.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/lomap_en1a/UI-3/docker-compose-deploy.yml -O docker-compose.yml
docker-compose stop
docker-compose rm -f
docker-compose pull
Expand Down
39 changes: 22 additions & 17 deletions restapi/api.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import express, { Request, Response, Router } from "express";
import { Factory } from "./src/Factory";
import { PlaceService } from "./src/business/place/PlaceService";
import { CommentService } from "./src/business/comment/CommentService";
import { ScoreService } from "./src/business/score/ScoreService";
import { PictureService } from "./src/business/picture/PictureService";
import express, { Request, Response, Router } from 'express';
import { Factory } from './src/Factory';
import { PlaceService } from './src/business/place/PlaceService';
import { CommentService } from './src/business/comment/CommentService';
import { ScoreService } from './src/business/score/ScoreService';
import { PictureService } from './src/business/picture/PictureService';
import cors from "cors";

const api: Router = express.Router();

let factory: Factory = new Factory();

const bodyParser = require("body-parser");
const cookieSession = require("cookie-session");
const cookieSession = require('cookie-session');
api.use(bodyParser.json());
api.use(
cookieSession({
Expand All @@ -23,16 +25,17 @@ api.use(
})
);

let host = process.env.host || "localhost";
let host = process.env.host || 'localhost';
api.use(
cors({
credentials: true,
origin: "https://" + host + "",
allowedHeaders: ["Content-Type", "Authorization"],
preflightContinue: true,
})
origin: 'http://'+host+':3000',
allowedHeaders: ['Content-Type', 'Authorization'],
preflightContinue: true
}),
);


//Place

let placeService: PlaceService = Factory.services.getPlaceService();
Expand Down Expand Up @@ -61,10 +64,12 @@ require("./src/controllers/pictures.ts")(api, pictureService);

require("./src/controllers/users.ts")(api);

api.get("/", async (req: Request, res: Response): Promise<Response> => {
res.send("Rest API for LoMap");
api.get("/",
async (req: Request, res: Response): Promise<Response> => {

res.send("Rest API for LoMap");

return res.status(200);
});
return res.status(200);
});

export default api;
export default api;
23 changes: 0 additions & 23 deletions restapi/certificates/host.cert

This file was deleted.

27 changes: 0 additions & 27 deletions restapi/certificates/host.key

This file was deleted.

63 changes: 27 additions & 36 deletions restapi/server.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,42 @@
import express, { Application, RequestHandler } from "express";
import cors from "cors";
import bp from "body-parser";
import promBundle from "express-prom-bundle";
import cors from 'cors';
import bp from 'body-parser';
import promBundle from 'express-prom-bundle';
import api from "./api";
import { DatabaseConnection } from "./src/repositories/DatabaseConnection";
import { readFileSync } from "fs";
import { createServer } from "https";

const app: Application = express();
const port: number = 5000;

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

let host = process.env.host || "localhost";

var privateKey = readFileSync("certificates/host.key");
var certificate = readFileSync("certificates/host.cert");
var credentials = { key: privateKey, cert: certificate };

app.all("*", function (req, res, next) {
if (req.secure) {
return next();
}
console.log("redirecting to https");
res.redirect("https://" + req.hostname + req.url);
});
let host = process.env.host || 'localhost';
api.use(
cors({
credentials: true,
origin: 'http://'+host+':3000',
allowedHeaders: ['Content-Type', 'Authorization'],
preflightContinue: true
}),
);

app.use(bp.json());

app.use("/api", api);
DatabaseConnection.setDatabase(
"mongodb+srv://admin:[email protected]/?retryWrites=true&w=majority" as string
);
app.use("/api", api)
DatabaseConnection.setDatabase("mongodb+srv://admin:[email protected]/?retryWrites=true&w=majority" as string);

// app
// .listen(port, (): void => {
// console.log("Restapi listening on " + port);
// })
// .on("error", (error: Error) => {
// console.error("Error occured: " + error.message);
// });
app.use(
cors({
credentials: true,
origin: 'http://'+host+':3000',
allowedHeaders: ['Content-Type', 'Authorization'],
preflightContinue: true
}),
);

createServer(credentials, app)
.listen(port, (): void => {
console.log("Restapi listening on " + port);
})
.on("error", (error: Error) => {
console.error("Error occured: " + error.message);
});
app.listen(port, (): void => {
console.log('Restapi listening on ' + port);
}).on("error", (error: Error) => {
console.error('Error occured: ' + error.message);
});
8 changes: 4 additions & 4 deletions restapi/src/repositories/pods/PodSessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class PodSessionManager {
provider = decodeURIComponent(provider);

let redirect = req.params.redirect;
redirect = "https://" + host + ":5000/api/login/success";
redirect = "http://" + host + ":5000/api/login/success";

const session = new Session();
req.session.solidSessionId = session.info.sessionId;
Expand All @@ -41,7 +41,7 @@ export class PodSessionManager {
},
});
} catch (err) {
res.redirect("https://" + host + ":443/login/fail");
res.redirect("http://" + host + ":3000/login/fail");
}
}

Expand All @@ -53,12 +53,12 @@ export class PodSessionManager {
let solidSession = await getSessionFromStorage(sessionId);

await solidSession?.handleIncomingRedirect(
`https://${host}${this.port}${this.handle}${req.url}`
`http://${host}${this.port}${this.handle}${req.url}`
);

await PodManager.permissionManager.setupPod(sessionId);

return res.redirect("https://" + host + ":443/map");
return res.redirect("http://" + host + ":3000/map");
}

public async logout(req: any, res: Response): Promise<any> {
Expand Down
2 changes: 0 additions & 2 deletions webapp/.env

This file was deleted.

2 changes: 1 addition & 1 deletion webapp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WORKDIR /app
#Install the dependencies
RUN npm install

ARG API_URI="https://20.38.6.214:443/api"
ARG API_URI="http://20.38.6.214:5000/api"
ENV REACT_APP_API_URI=$API_URI

ARG HOST_URI="20.38.6.214"
Expand Down
2 changes: 1 addition & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --transformIgnorePatterns \"node_modules/(?!ol)/\" --coverage",
"test:e2e": "start-server-and-test 'npm --prefix ../restapi run start' https://localhost:5000/api start 3000 \"cd e2e && jest\"",
"test:e2e": "start-server-and-test 'npm --prefix ../restapi run start' http://localhost:5000/api start 3000 \"cd e2e && jest\"",
"eject": "react-scripts eject",
"prod": "ts-node-dev ./server.ts"
},
Expand Down
Loading

0 comments on commit a3cb07d

Please sign in to comment.