Skip to content

Commit

Permalink
Added a trigger to use full URL directly without appending /Default.aspx
Browse files Browse the repository at this point in the history
  • Loading branch information
developerfromjokela committed Apr 5, 2021
1 parent 05cc2fe commit 998aa96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "foodmenu",
"version": "1.0.2",
"version": "1.0.3",
"description": "This API provides additional food menus which are not available as JSON.\nThis middleware converts them to JSON format.",
"main": "build/main.js",
"scripts": {
Expand Down
14 changes: 11 additions & 3 deletions src/handlers/aromav2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ export function getMenuOptions(req: Request, res: Response) {
return;
}
let url = req.params.url;
let fullUrl = url.includes("aromiv2://");
url = url.replace("aromiv2://", "https://");
if (!url.match(urlRegex)) {
responseStatus(res, 400, false, {cause: 'Invalid of malformed URL!'});
return;
Expand All @@ -176,7 +178,7 @@ export function getMenuOptions(req: Request, res: Response) {
options.addArguments((global as any).seleniumArgs.split(","));
}
const driver = new Builder().forBrowser("chrome").setChromeOptions(options).build();
driver.get(url+"/Default.aspx").then(() => {
driver.get(url+(fullUrl ? "" : "/Default.aspx")).then(() => {
getRestaurantList(driver).then(restaurants => {
userCache.setItem(hashKey, restaurants, {ttl: 3600}).then(() => {
responseStatus(res, 200, true, {restaurants});
Expand Down Expand Up @@ -207,6 +209,12 @@ export function getRestaurantPage(req: Request, res: Response) {
}
let url = req.params.url;
let id = req.params.id;
let fullUrl = url.includes("aromiv2://");
url = url.replace("aromiv2://", "https://");
if (!url.match(urlRegex)) {
responseStatus(res, 400, false, {cause: 'Invalid of malformed URL!'});
return;
}
if (!url.match(urlRegex)) {
responseStatus(res, 400, false, {cause: 'Invalid of malformed URL!'});
return;
Expand Down Expand Up @@ -256,11 +264,11 @@ export function getRestaurantPage(req: Request, res: Response) {
options.addArguments((global as any).seleniumArgs.split(","));
}
const driver = new Builder().forBrowser("chrome").setChromeOptions(options).build();
driver.get(url+"/Default.aspx").then(() => {
driver.get(url+(fullUrl ? "" : "/Default.aspx")).then(() => {
selectRestaurant(driver, id).then(() => {
getRestaurantPDFLink(driver).then(pdfUrl => {
driver.close();
if (url == null) {
if (pdfUrl == null) {
responseStatus(res, 200, true, {menu: [], diets: []});
return;
}
Expand Down

0 comments on commit 998aa96

Please sign in to comment.