-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
47 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
import express from "express" | ||
import cors from 'cors' | ||
import { getFavorites,getFavoriteDescription } from "./controllers/favoriteController.js" | ||
const app =express() | ||
app.use(cors()) | ||
const port = 5000 | ||
import express from "express"; | ||
import cors from "cors"; | ||
import { | ||
getFavorites, | ||
getFavoriteDescription, | ||
} from "./controllers/favoriteController.js"; | ||
const app = express(); | ||
app.use(cors()); | ||
const port = 3000; | ||
|
||
app.get("/api/favorites",(req,res)=>{ | ||
getFavorites(req,res) | ||
}) | ||
app.get("/api/favorites", (req, res) => { | ||
getFavorites(req, res); | ||
}); | ||
|
||
app.get("/api/favorites/:cityname", (req,res)=>{ | ||
getFavoriteDescription(req,res) | ||
}) | ||
app.get("/api/favorites/:cityname", (req, res) => { | ||
getFavoriteDescription(req, res); | ||
}); | ||
|
||
app.use((err, req, res, next) => { | ||
res.status(500).json({ error: 'Something went wrong' }); | ||
}); | ||
res.status(500).json({ error: "Something went wrong" }); | ||
}); | ||
|
||
app.listen(port ,()=>{ | ||
console.log("Server started 300") | ||
}) | ||
app.listen(port, () => { | ||
console.log("Server started 300"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,28 @@ | ||
import { Injectable , EventEmitter } from '@angular/core'; | ||
import { Injectable, EventEmitter } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { BackendApiResponse } from '../dataTypes'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class BackendService { | ||
constructor(private http : HttpClient) {} | ||
apiUrl = "http://127.0.0.1:5000/api/favorites/" | ||
constructor(private http: HttpClient) {} | ||
apiUrl = 'http://127.0.0.1:3000/api/favorites/'; | ||
backendApiServiceStatus = new EventEmitter<Object>(); | ||
getFavoriteCities() { | ||
return this.http.get(this.apiUrl) | ||
getFavoriteCities() { | ||
return this.http.get(this.apiUrl); | ||
} | ||
|
||
getCityDescriptionByName(cityName:string){ | ||
this.http.get(this.apiUrl+cityName).subscribe((val:any)=>{ | ||
if(val){ | ||
getCityDescriptionByName(cityName: string) { | ||
this.http.get(this.apiUrl + cityName).subscribe((val: any) => { | ||
if (val) { | ||
this.backendApiServiceStatus.emit({ | ||
data: val, | ||
loading: false, | ||
error: '', | ||
}) | ||
}else{ | ||
|
||
} | ||
}) | ||
}); | ||
} else { | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters