Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
danmgs committed Dec 10, 2020
1 parent 5b53223 commit efa08a3
Show file tree
Hide file tree
Showing 35 changed files with 480 additions and 288 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ NODE_ENV=production
ENV_SERVER_API_MONGODB_URI=mongodb://mongo-service:27017
ENV_SERVER_API_ALLOW_HOSTS=*
ENV_SERVER_API_PORT=30001
ENV_API_KEY_DARKSKY=<YOUR_ENV_API_KEY_DARKSKY>
ENV_API_KEY_NEWS=<YOUR_ENV_API_KEY_NEWS>

ENV_WEBAPP_NODE_ENV=prod
ENV_WEBAPP_PORT=80
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# dependencies
/node_modules


# IDEs and editors
/.idea
.project
Expand Down Expand Up @@ -46,3 +47,5 @@ Thumbs.db
# Output log
log
server/package-lock.json

/.scannerwork
11 changes: 8 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"files.autoSave": "onFocusChange"
}
{
"files.autoSave": "onFocusChange",
"sonarlint.connectedMode.project": {
"connectionId": "mysonarqube",
"projectKey": "My-weather-app"
},
"git.ignoreLimitWarning": true
}
8 changes: 8 additions & 0 deletions Dockerrun.aws.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
{
"name": "ENV_SERVER_API_PORT",
"value": "30001"
},
{
"name": "ENV_API_KEY_DARKSKY",
"value": "<YOUR_ENV_API_KEY_DARKSKY>"
},
{
"name": "ENV_API_KEY_NEWS",
"value": "<YOUR_ENV_API_KEY_NEWS>"
}
],
"essential": true,
Expand Down
2 changes: 2 additions & 0 deletions docker-compose-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ services:
ENV_SERVER_API_MONGODB_URI: mongodb://mongo-service:27017
ENV_SERVER_API_ALLOW_HOSTS: "*"
ENV_SERVER_API_PORT: 30001
ENV_API_KEY_DARKSKY: <YOUR_ENV_API_KEY_DARKSKY>
ENV_API_KEY_NEWS: <YOUR_ENV_API_KEY_NEWS>
ports:
- "30001:30001"
depends_on:
Expand Down
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ services:
- mongodata:/data/db
restart: always

mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
environment:
# ME_CONFIG_MONGODB_ADMINUSERNAME: root
# ME_CONFIG_MONGODB_ADMINPASSWORD: example
ME_CONFIG_MONGODB_SERVER: mongo-service

app-backend:
build:
context: ./server
Expand All @@ -19,6 +29,8 @@ services:
ENV_SERVER_API_MONGODB_URI: ${ENV_SERVER_API_MONGODB_URI}
ENV_SERVER_API_ALLOW_HOSTS: ${ENV_SERVER_API_ALLOW_HOSTS}
ENV_SERVER_API_PORT: ${ENV_SERVER_API_PORT}
ENV_API_KEY_DARKSKY: ${ENV_API_KEY_DARKSKY}
ENV_API_KEY_NEWS: ${ENV_API_KEY_NEWS}
ports:
- ${ENV_SERVER_API_PORT}:${ENV_SERVER_API_PORT}
depends_on:
Expand Down
1 change: 1 addition & 0 deletions launch.bat
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ IF "%1"=="up" (
timeout /t 10 /nobreak > NUL
START "" http://localhost
START "" http://localhost:30001/api/serverhealth
START "" http://localhost:8081
GOTO End
)

Expand Down
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions public/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@ server {
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}

location /api {
proxy_pass http://app-backend:30001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
16 changes: 8 additions & 8 deletions public/src/app/Shared/GeoData.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export class GeoData {

constructor(
public lat: number,
public lng: number,
public formatted_address: String
) { }
}
export class GeoData {

constructor(
public lat: Number,
public lng: Number,
public formatted_address: String
) { }
}
7 changes: 7 additions & 0 deletions public/src/app/Shared/ServerHealthData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class ServerHealthData {

constructor(
public status: String,
public text: String
) { }
}
80 changes: 40 additions & 40 deletions public/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

/** Modules by feature **/
import { WeatherModule } from './views/weather/weather.module';
import { NewsModule } from './views/news/news.module';
import { QuoteModule } from './views/quote-list/quote.module';
import { PrimeNgModule } from './primeng.module';
import { CustomFiltersModule } from './customfilters.module';

import { AppComponent } from './app.component';
import { HeaderComponent } from './views/header/header.component';
import { FooterComponent } from './views/footer/footer.component';

import { AppRoutingModule } from './app-routing.module';

@NgModule({
declarations: [
AppComponent,
HeaderComponent,
FooterComponent
],
imports: [
BrowserModule,
AppRoutingModule,
HttpModule,
FormsModule,
BrowserAnimationsModule,
CustomFiltersModule,
PrimeNgModule,
WeatherModule,
NewsModule,
QuoteModule
],
bootstrap: [AppComponent]
})
export class AppModule { }
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

/** Modules by feature **/
import { HeaderModule } from './views/header/header.module';
import { WeatherModule } from './views/weather/weather.module';
import { NewsModule } from './views/news/news.module';
import { QuoteModule } from './views/quote-list/quote.module';
import { PrimeNgModule } from './primeng.module';
import { CustomFiltersModule } from './customfilters.module';

import { AppComponent } from './app.component';
import { FooterComponent } from './views/footer/footer.component';

import { AppRoutingModule } from './app-routing.module';

@NgModule({
declarations: [
AppComponent,
FooterComponent
],
imports: [
BrowserModule,
AppRoutingModule,
HttpModule,
FormsModule,
BrowserAnimationsModule,
CustomFiltersModule,
PrimeNgModule,
HeaderModule,
WeatherModule,
NewsModule,
QuoteModule
],
bootstrap: [AppComponent]
})
export class AppModule { }
8 changes: 1 addition & 7 deletions public/src/app/services/geo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@ import { Observable } from 'rxjs/Observable';

import { GeoData } from '../Shared/GeoData';

import { environment } from '../../environments/environment';

@Injectable()
export class GeoService {

constructor(private http: Http) { }

getGeoCode(address: String) {

<<<<<<< HEAD
const url = `${environment.serverUrl}/api/geo?address=${address}`;
=======
const url = `http://${environment.apiUrl}:${environment.apiPort}/api/geo?address=${address}`;
>>>>>>> dockerization-branch
const url = `${environment.apiUrl}/api/geo?address=${address}`;
// console.log('getGeoCode', url);
return this.http.get(url)
.map(
Expand Down
4 changes: 2 additions & 2 deletions public/src/app/services/news.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class NewsService {

getSources(language: String, category: String, country: String) {

const url = `${environment.serverUrl}/api/news/sources?language=${language}&category=${category}&country=${country}`;
const url = `${environment.apiUrl}/api/news/sources?language=${language}&category=${category}&country=${country}`;
console.log('getSources', url);
return this.http.get(url)
.map(
Expand All @@ -42,7 +42,7 @@ export class NewsService {

getArticles(source: String, sortBy: String) {

const url = `${environment.serverUrl}/api/news/articles?source=${source}&sortBy=${sortBy}`;
const url = `${environment.apiUrl}/api/news/articles?source=${source}&sortBy=${sortBy}`;
console.log('getArticles', url);
return this.http.get(url)
.map(
Expand Down
4 changes: 2 additions & 2 deletions public/src/app/services/quote.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class QuoteService {

getQuotes(symbol: String, from: String, to: String) {

const url = `${environment.serverUrl}/api/finance/quotes?symbol=${symbol}&from=${from}&to=${to}`;
const url = `${environment.apiUrl}/api/finance/quotes?symbol=${symbol}&from=${from}&to=${to}`;
// console.log('getQuotes', url);
return this.http.get(url)
.map(
Expand All @@ -41,7 +41,7 @@ export class QuoteService {

getCompanyNews(symbol: String) {

const url = `${environment.serverUrl}/api/finance/companynews?symbol=${symbol}`;
const url = `${environment.apiUrl}/api/finance/companynews?symbol=${symbol}`;
// console.log('getCompanyNews', url);
return this.http.get(url)
.map(
Expand Down
27 changes: 27 additions & 0 deletions public/src/app/services/serverhealth.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { environment } from '../../environments/environment';
import 'rxjs/Rx';

import { ServerHealthData } from '../Shared/ServerHealthData';

@Injectable()
export class ServerHealthService {

constructor(private http: Http) { }

check() {

const url = `${environment.apiUrl}/api/serverhealth`;
return this.http.get(url)
.map(
(response: Response) => {
const res = response.json();
return new ServerHealthData(
res.status,
res.text);
}
);
}

}
27 changes: 19 additions & 8 deletions public/src/app/services/weather.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,20 @@ export class WeatherService {
);
}

getForecastByGeoCode(geodata: GeoData) {

this.getForecastInfos(geodata)
.subscribe(
(weatherdata: WeatherData) => {
this.weatherChanged.next(weatherdata);
},
(error) => console.log(error)
);
}

private getForecastInfos(geodata: GeoData) {

const url = `${environment.serverUrl}/api/weather/${geodata.lat}/${geodata.lng}`;
const url = `${environment.apiUrl}/api/weather/${geodata.lat}/${geodata.lng}`;

return this.http.post(url, {}/*, options */)
.map(
Expand All @@ -66,7 +77,7 @@ export class WeatherService {

getFavorites() {

const url = `${environment.serverUrl}/api/weather/favorites`;
const url = `${environment.apiUrl}/api/weather/favorites`;
console.log('getFavorites', url);
return this.http.get(url)
.subscribe(
Expand All @@ -79,7 +90,7 @@ export class WeatherService {

getFavorite(address: String) {

const url = `${environment.serverUrl}/api/weather/favorites/${address}`;
const url = `${environment.apiUrl}/api/weather/favorites/${address}`;
console.log('getFavorite', url);
return this.http.get(url)
.map(
Expand All @@ -96,7 +107,7 @@ export class WeatherService {

addFavoriteWithCheck(address: String) {

const url = `${environment.serverUrl}/api/weather/favorites/check`;
const url = `${environment.apiUrl}/api/weather/favorites/check`;
// console.log(`Calling addFavoriteWithCheck with ${url} ${address}`);
return this.http.post(url, { address })
.map(
Expand All @@ -112,7 +123,7 @@ export class WeatherService {

addFavorite(address: String) {

const url = `${environment.serverUrl}/api/weather/favorites`;
const url = `${environment.apiUrl}/api/weather/favorites`;
// console.log(`Calling getFavorites with ${url} ${address}`);
return this.http.post(url, { address })
.map(
Expand All @@ -124,7 +135,7 @@ export class WeatherService {

deleteFromFavorites(id: String) {

const url = `${environment.serverUrl}/api/weather/favorites/${id}`;
const url = `${environment.apiUrl}/api/weather/favorites/${id}`;
// console.log(`Calling deleteFromFavorites with ${url}`);
return this.http.delete(url);
}
Expand All @@ -133,7 +144,7 @@ export class WeatherService {

this.weatherFavoritesResponse = [];

const url = `${environment.serverUrl}/api/weather/favorites/active/true`;
const url = `${environment.apiUrl}/api/weather/favorites/active/true`;
// console.log(`Calling getForecastForFavoritesActive with ${url}`);
this.http.get(url)
.subscribe(
Expand All @@ -153,7 +164,7 @@ export class WeatherService {

editFavoriteStatus(id: String, activeStatus: Boolean) {

const url = `${environment.serverUrl}/api/weather/favorites/${id}`;
const url = `${environment.apiUrl}/api/weather/favorites/${id}`;
// console.log(`Calling editFavoriteStatus with ${id} ${activeStatus}`);
return this.http.put(url, { active: activeStatus })
.subscribe(
Expand Down
5 changes: 5 additions & 0 deletions public/src/app/views/header/header.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@
.env-css-prod {
color: red;
}

.api-status {
text-align: right;
}

Loading

0 comments on commit efa08a3

Please sign in to comment.