Skip to content

Commit

Permalink
Merge pull request #22 from ssysm/update
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
ssysm authored Mar 24, 2018
2 parents 28cdd3b + 4d0d9cf commit 242a029
Show file tree
Hide file tree
Showing 46 changed files with 2,105 additions and 596 deletions.
1 change: 1 addition & 0 deletions client/.angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
],
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/popper.js/dist/umd/popper.min.js",
"../node_modules/bootstrap/dist/js/bootstrap.min.js"
],
"environmentSource": "environments/environment.ts",
Expand Down
1,127 changes: 656 additions & 471 deletions client/package-lock.json

Large diffs are not rendered by default.

37 changes: 19 additions & 18 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,45 @@
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"analyzer": "webpack-bundle-analyzer dist/stats.json"
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^5.2.6",
"@angular/common": "^5.2.6",
"@angular/compiler": "^5.2.6",
"@angular/core": "^5.2.6",
"@angular/forms": "^5.2.6",
"@angular/http": "^5.2.6",
"@angular/platform-browser": "^5.2.6",
"@angular/platform-browser-dynamic": "^5.2.6",
"@angular/router": "^5.2.6",
"@angular/service-worker": "^5.2.6",
"axios": "^0.18.0",
"@angular/animations": "^5.2.7",
"@angular/common": "^5.2.7",
"@angular/compiler": "^5.2.7",
"@angular/core": "^5.2.7",
"@angular/forms": "^5.2.7",
"@angular/http": "^5.2.7",
"@angular/platform-browser": "^5.2.7",
"@angular/platform-browser-dynamic": "^5.2.7",
"@angular/router": "^5.2.7",
"@angular/service-worker": "^5.2.7",
"bootstrap": "^4.0.0",
"core-js": "^2.4.1",
"express": "^4.16.2",
"flag-icon-css": "^3.0.0",
"jquery": "^3.3.1",
"node-fetch": "^2.1.1",
"popper.js": "^1.14.1",
"rxjs": "^5.5.2",
"sweetalert": "^2.1.0",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "^1.7.1",
"@angular/compiler-cli": "^5.2.6",
"@angular/language-service": "^5.2.6",
"@angular/cli": "^1.7.2",
"@angular/compiler-cli": "^5.2.7",
"@angular/language-service": "^5.2.7",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "^6.0.101",
"codelyzer": "^4.0.1",
"codelyzer": "^4.2.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-coverage-istanbul-reporter": "^1.4.2",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
Expand Down
98 changes: 87 additions & 11 deletions client/proxy.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,96 @@
const express = require('express');
const axios = require('axios');

const fetch = require('node-fetch');
const url = require('url');
const appUri = "https://starrysea.org/";
const renderUri = "http://localhost:8080/render";
const renderUri = "https://rendertron.tes-project.xyz/render";

const app = express();

app.get('*',(req,res)=>{

axios.get(`${renderUri}/${appUri + req.originalUrl}`)
.then((data)=>{
res.set('Cache-Control','public, max-age=300, s-maxage=600');
res.send(data.data.toString());
})
// Generates the URL
function generateUrl(request) {
return url.format({
protocol: request.protocol,
host: appUrl,
pathname: request.originalUrl
});
}

});
function detectBot(userAgent) {
// List of bots to target, add more if you'd like

const bots = [
// crawler bots
'googlebot',
'bingbot',
'yandexbot',
'duckduckbot',
'slurp',
// link bots
'twitterbot',
'facebookexternalhit',
'linkedinbot',
'embedly',
'baiduspider',
'pinterest',
'slackbot',
'vkShare',
'facebot',
'outbrain',
'W3C_Validator'
]

const agent = userAgent.toLowerCase();

for (const bot of bots) {
if (agent.indexOf(bot) > -1) {
console.log('bot detected', bot, agent)
return true
}
}

console.log('no bots found')
return false

}


app.get('*', (req, res) => {


const isBot = detectBot(req.headers['user-agent']);


app.listen(4300);
if (isBot) {

const botUrl = generateUrl(req);
// If Bot, fetch url via rendertron

fetch(`${renderUri}/${botUrl}`)
.then(res => res.text() )
.then(body => {

// Set the Vary header to cache the user agent, based on code from:
// https://github.com/justinribeiro/pwa-firebase-functions-botrender
res.set('Cache-Control', 'public, max-age=300, s-maxage=600');
res.set('Vary', 'User-Agent');

res.send(body.toString())

});

} else {


// Not a bot, fetch the regular Angular app
// Possibly faster to serve directly from from the functions directory?
fetch(`${appUri}`)
.then(res => res.text())
.then(body => {
res.send(body.toString());
})
}

});

app.listen(4400);
8 changes: 6 additions & 2 deletions client/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Component, OnInit,HostBinding, ViewChild} from '@angular/core';
import {Component, OnInit} from '@angular/core';
import {routeAnimation} from "./common/animation";
import {LocaleService} from "./service/locale.service";

@Component({
selector: 'app-root',
Expand All @@ -10,12 +11,15 @@ import {routeAnimation} from "./common/animation";
export class AppComponent implements OnInit{

loaded:Boolean = false;
constructor(){
constructor(
private locale:LocaleService
){

}

ngOnInit(){
this.loaded = true;
this.locale.onInit();
}

public getRouteAnimation(outlet) {
Expand Down
73 changes: 39 additions & 34 deletions client/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ServiceWorkerModule } from '@angular/service-worker';
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {ServiceWorkerModule} from '@angular/service-worker';


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

import { AppComponent } from './app.component';
import { HomeComponent } from './view/home/home.component';
import { ActivityService } from './service/activity.service';
import { FundingService } from './service/funding.service';
import { WorkService } from './service/work.service';
import { WorkComponent } from './view/work/work.component';
import { ActivityComponent } from './view/activity/activity.component';
import { NavbarComponent } from './view/partical/navbar/navbar.component';
import { ActivityDetailComponent } from './view/activity-detail/activity-detail.component';
import { WorkDetailComponent } from './view/work-detail/work-detail.component';
import { NotFoundComponent } from './view/partical/not-found/not-found.component';
import { AboutComponent } from './view/about/about.component';
import { DashboardComponent } from './view/admin/dashboard/dashboard.component';
import { UserManagementComponent } from './view/admin/user-management/user-management.component';
import { ActivityManagementComponent } from './view/admin/activity-management/activity-management.component';
import { WorkManagementComponent } from './view/admin/work-management/work-management.component';
import {AppComponent} from './app.component';
import {HomeComponent} from './view/home/home.component';
import {ActivityService} from './service/activity.service';
import {FundingService} from './service/funding.service';
import {WorkService} from './service/work.service';
import {WorkComponent} from './view/work/work.component';
import {ActivityComponent} from './view/activity/activity.component';
import {NavbarComponent} from './view/partical/navbar/navbar.component';
import {ActivityDetailComponent} from './view/activity-detail/activity-detail.component';
import {WorkDetailComponent} from './view/work-detail/work-detail.component';
import {NotFoundComponent} from './view/partical/not-found/not-found.component';
import {AboutComponent} from './view/about/about.component';
import {DashboardComponent} from './view/admin/dashboard/dashboard.component';
import {UserManagementComponent} from './view/admin/user-management/user-management.component';
import {ActivityManagementComponent} from './view/admin/activity-management/activity-management.component';
import {WorkManagementComponent} from './view/admin/work-management/work-management.component';
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
import {HttpModule, BrowserXhr} from "@angular/http";
import {cros} from "./common/cros";
import { FooterComponent } from './view/partical/footer/footer.component';
import {FooterComponent} from './view/partical/footer/footer.component';
import {AdminGuardService} from "./common/guard/admin-guard.service";
import { AuthComponent } from './view/admin/auth/auth.component';
import {AuthComponent} from './view/admin/auth/auth.component';
import {AuthService} from "./service/auth.service";
import { FundingManagementComponent } from './view/admin/funding-management/funding-management.component';
import {FundingManagementComponent} from './view/admin/funding-management/funding-management.component';
import {VersionService} from "./service/version.service";
import {environment} from "../environments/environment";
import { QaComponent } from './view/qa/qa.component';
import { QaService } from './service/qa.service';
import { QaManagementComponent } from './view/admin/qa-management/qa-management.component';
import { TextSlicePipe } from './common/pipe/text-slice.pipe';
import { SpinnerComponent } from './view/partical/spinner/spinner.component';
import {QaComponent} from './view/qa/qa.component';
import {QaService} from './service/qa.service';
import {QaManagementComponent} from './view/admin/qa-management/qa-management.component';
import {TextSlicePipe} from './common/pipe/text-slice.pipe';
import {SpinnerComponent} from './view/partical/spinner/spinner.component';
import {BrowserAnimationsModule} from "@angular/platform-browser/animations";
import { WorkListComponent } from './view/admin/work-list/work-list.component';
import { ActivityListComponent } from './view/admin/activity-list/activity-list.component';
import {WorkListComponent} from './view/admin/work-list/work-list.component';
import {ActivityListComponent} from './view/admin/activity-list/activity-list.component';
import {LocaleService} from "./service/locale.service";
import {CookieService} from "./service/cookie.service";


@NgModule({
Expand Down Expand Up @@ -82,12 +84,15 @@ import { ActivityListComponent } from './view/admin/activity-list/activity-list.
WorkService,
AdminGuardService,
VersionService,
LocaleService,
{
provide: BrowserXhr,
useClass:cros,
provide: BrowserXhr,
useClass: cros,
},
QaService
QaService,
CookieService
],
bootstrap: [AppComponent]
})
export class AppModule { }
export class AppModule {
}
5 changes: 5 additions & 0 deletions client/src/app/common/locale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const locale = [
"en-US",
"ja-JP",
"zh-CN"
];
6 changes: 4 additions & 2 deletions client/src/app/service/activity.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { Injectable } from '@angular/core';
import {Http, RequestOptions} from "@angular/http";
import {environment} from "../../environments/environment";
import {LocaleService} from "./locale.service";

@Injectable()
export class ActivityService {

constructor(
private http:Http
private http:Http,
private locale:LocaleService
) { }

fetchActivityList(page:Number,limit:Number){
return this.http
.get(environment.apiBase+'/activity?page='+page+'&limit='+limit)
.get(environment.apiBase+'/activity?page='+page+'&limit='+limit+'&locale='+this.locale.getLocale())
}

getActivity(uid:String){
Expand Down
46 changes: 46 additions & 0 deletions client/src/app/service/cookie.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Injectable } from '@angular/core';
import {environment} from "../../environments/environment";

@Injectable()
export class CookieService {

constructor() { }

setCookie(cookieName:string,cookieValue:string,expireDays:number) :string {
var d = new Date();
d.setTime(d.getTime() + (expireDays*24*60*60*1000));
var expires = "expires=" + d.toUTCString();
return document.cookie = cookieName + "=" + cookieValue + ";" + expires + ";path=/;domain="+environment.cookieDomain+';';
}


getCookie(cookieName:string): string {
var name = cookieName + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}

deleteCookie(): void{
var cookies = document.cookie.split(";");

for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var eqPos = cookie.indexOf("=");
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT;domain="+environment.cookieDomain+';';
}
}



}
Loading

0 comments on commit 242a029

Please sign in to comment.