Skip to content

Commit ebe2f2c

Browse files
committed
add special html file for china, and use special google maps url
1 parent 27c206c commit ebe2f2c

8 files changed

Lines changed: 95 additions & 40 deletions

File tree

public/_redirects

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/cn.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
7+
<meta
8+
name="description"
9+
content="Great Circle Map displays the shortest
10+
route between airports and calculates the distance. It draws geodesic flight
11+
paths on top of Google maps, so you can create your own route map."
12+
/>
13+
<title>Great Circle Map</title>
14+
</head>
15+
<body>
16+
<div id="app"></div>
17+
<script>
18+
window.COUNTRY = 'cn';
19+
</script>
20+
<script src="/bundle.js"></script>
21+
</body>
22+
</html>

public/netlify.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[[redirects]]
2+
from = "/*"
3+
to = "/cn.html"
4+
status = 200
5+
force = false
6+
[[redirects]]
7+
from = "/*"
8+
to = "/index.html"
9+
status = 200
10+
force = false

server.js

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
1-
const path = require("path")
2-
const express = require("express")
3-
const favicon = require("serve-favicon")
4-
const cookieParser = require("cookie-parser")
5-
const bodyParser = require("body-parser")
6-
const session = require("express-session")
7-
const compression = require("compression")
1+
const path = require('path');
2+
const express = require('express');
3+
const favicon = require('serve-favicon');
4+
const cookieParser = require('cookie-parser');
5+
const bodyParser = require('body-parser');
6+
const session = require('express-session');
7+
const compression = require('compression');
88

9-
const port = process.env.PORT || "3000"
10-
const app = express()
9+
const port = process.env.PORT || '3000';
10+
const app = express();
1111

12-
app.use(compression())
13-
app.use(favicon(path.join(__dirname, "public", "favicon.ico")))
14-
app.use(bodyParser.json())
15-
app.use(bodyParser.urlencoded({ extended: false }))
16-
app.use(cookieParser())
17-
app.use(session({ // REMOVE IF NOT NEEDED
18-
secret: "What is this secret for??", // CHANGE!
19-
resave: false,
20-
saveUninitialized: false
21-
}))
12+
app.use(compression());
13+
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
14+
app.use(bodyParser.json());
15+
app.use(bodyParser.urlencoded({ extended: false }));
16+
app.use(cookieParser());
17+
app.use(
18+
session({
19+
// REMOVE IF NOT NEEDED
20+
secret: 'What is this secret for??', // CHANGE!
21+
resave: false,
22+
saveUninitialized: false
23+
})
24+
);
2225

23-
app.use(express.static(path.join(__dirname, "public")))
26+
app.use(express.static(path.join(__dirname, 'public')));
2427

25-
app.get("*", (req, res) => {
26-
res.sendFile(path.join(__dirname, "public", "index.html"))
27-
})
28+
app.get('*', (req, res) => {
29+
res.sendFile(path.join(__dirname, 'public', 'index.html'));
30+
});
2831

2932
/* eslint-disable no-console */
30-
app.listen(port, () => console.log(`Server listening on port ${port}`))
33+
app.listen(port, () => console.log(`Server listening on port ${port}`));
3134
/* eslint-enable no-console */

src/components/GoogleMapWrapper.jsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React, { Component } from 'react';
21
import PropTypes from 'prop-types';
2+
import React, { Component } from 'react';
33
import { connect } from 'react-redux';
4-
import { getRoutes, getAirports, getSectors, getBrighterColor } from '../selectors';
4+
import { getAirports, getBrighterColor, getRoutes, getSectors } from '../selectors';
55
import GoogleMap from './GoogleMap';
66

77
class GoogleMapWrapper extends Component {
@@ -46,10 +46,21 @@ class GoogleMapWrapper extends Component {
4646
}
4747

4848
render() {
49-
const { routes, airports, sectors, mapType, label, routeColor, pointColor, map } = this.props;
49+
const {
50+
routes,
51+
airports,
52+
sectors,
53+
mapType,
54+
label,
55+
routeColor,
56+
pointColor,
57+
map,
58+
country
59+
} = this.props;
60+
const rootUrl = country === 'cn' ? 'http://maps.google.cn' : 'https://maps.googleapis.com';
5061
return (
5162
<GoogleMap
52-
googleMapURL="https://maps.googleapis.com/maps/api/js?v=3.exp&key=AIzaSyBISa-Ul-NOnD-H5lweC_w4evLmV_0fuSU"
63+
googleMapURL={`${rootUrl}/maps/api/js?v=3.exp&key=AIzaSyBISa-Ul-NOnD-H5lweC_w4evLmV_0fuSU`}
5364
loadingElement={<div style={{ height: '100%' }} />}
5465
containerElement={<div id="map-container" />}
5566
mapElement={<div id="map" />}
@@ -67,6 +78,7 @@ class GoogleMapWrapper extends Component {
6778
}
6879
}
6980
GoogleMapWrapper.propTypes = {
81+
country: PropTypes.string,
7082
dispatch: PropTypes.func.isRequired,
7183
routes: PropTypes.arrayOf(PropTypes.array),
7284
sectors: PropTypes.arrayOf(PropTypes.array).isRequired,
@@ -83,6 +95,7 @@ GoogleMapWrapper.defaultProps = { map: null, routes: null };
8395

8496
function mapStateToProps(state) {
8597
return {
98+
country: state.country,
8699
routes: getRoutes(state).routes,
87100
sectors: getSectors(state),
88101
airports: getAirports(state),

src/index.jsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import 'babel-polyfill';
2+
import createBrowserHistory from 'history/createBrowserHistory';
23
import React from 'react';
34
import ReactDOM from 'react-dom';
4-
import { createStore, applyMiddleware, combineReducers, compose } from 'redux';
55
import { Provider } from 'react-redux';
6+
import { applyMiddleware, combineReducers, compose, createStore } from 'redux';
67
import { routerForBrowser } from 'redux-little-router';
7-
import createBrowserHistory from 'history/createBrowserHistory';
8-
import ReduxThunk from 'redux-thunk';
98
// import logger from 'redux-logger';
10-
11-
import './stylesheets/styles.scss';
12-
import './stylesheets/map.scss';
13-
14-
import reducers from './reducers';
9+
import ReduxThunk from 'redux-thunk';
1510
import App from './components/App';
11+
import reducers from './reducers';
12+
import './stylesheets/map.scss';
13+
import './stylesheets/styles.scss';
1614
import checkIfMobile from './utils/checkIfMobile';
1715

1816
const history = createBrowserHistory();
@@ -57,9 +55,12 @@ const { reducer, middleware, enhancer } = routerForBrowser({
5755
routes
5856
});
5957

58+
const country = window.COUNTRY;
59+
delete window.COUNTRY;
60+
6061
const store = createStore(
6162
combineReducers({ ...reducers, router: reducer }),
62-
{ isMobile: checkIfMobile() },
63+
{ isMobile: checkIfMobile(), country },
6364
compose(
6465
enhancer,
6566
applyMiddleware(ReduxThunk, middleware)

src/reducers/country.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const country = (state = null) => {
2+
return state;
3+
};
4+
5+
export default country;

src/reducers/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import airportData from './airportData';
2-
import map from './map';
2+
import country from './country';
33
import inputMode from './inputMode';
4-
import settings from './settings';
54
import isMobile from './isMobile';
5+
import map from './map';
66
import searchInput from './searchInput';
7+
import settings from './settings';
78
import svgMap from './svgMap';
89

910
export default {
1011
airportData,
12+
country,
1113
map,
1214
inputMode,
1315
settings,

0 commit comments

Comments
 (0)