Skip to content

Commit

Permalink
support ssl
Browse files Browse the repository at this point in the history
  • Loading branch information
teddy-ma committed Jul 11, 2016
1 parent b4f726c commit 1d10cea
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 33 deletions.
29 changes: 12 additions & 17 deletions client/dist/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
/******/ }
/******/
/******/ var hotApplyOnUpdate = true;
/******/ var hotCurrentHash = "96b469f4d4d522ce41fb"; // eslint-disable-line no-unused-vars
/******/ var hotCurrentHash = "c4f276629b4d7785763a"; // eslint-disable-line no-unused-vars
/******/ var hotCurrentModuleData = {};
/******/ var hotCurrentParents = []; // eslint-disable-line no-unused-vars
/******/
Expand Down Expand Up @@ -8213,20 +8213,14 @@
var repo = script_tag.dataset.repo;
var page_id = script_tag.dataset.pageId;
var server_url = script_tag.dataset.serverUrl || 'github-comment.herokuapp.com';
var ssl = script_tag.dataset.ssl || false;
var wrapper_id = 'github-comments';

// 定义 url 接口地址
var COMMENTS_URL = 'http://' + server_url + '/comments?page_id=' + page_id + '&user_name=' + user_name + '&repo=' + repo;
var AUTH_URL = 'http://' + server_url + '/users/auth';

// 创建 store
var createStoreDevTools = (0, _redux.compose)(window.devToolsExtension ? window.devToolsExtension() : function (f) {
return f;
})(_redux.createStore);
var store = createStoreDevTools(_reducer2.default);
var store = (0, _redux.createStore)(_reducer2.default);

// 初始化基础信息
store.dispatch({ type: 'INIT_APP', user_name: user_name, repo: repo, page_id: page_id, server_url: server_url });
store.dispatch({ type: 'INIT_APP', user_name: user_name, repo: repo, page_id: page_id, server_url: server_url, ssl: ssl });
// 初始化评论列表
store.dispatch({ type: 'LOAD_COMMENTS', user_name: user_name, repo: repo, page_id: page_id });
// 初始化登录状态
Expand Down Expand Up @@ -35379,7 +35373,8 @@
user_name: '',
repo: '',
page_id: '',
server_url: ''
server_url: '',
ssl: false
},
comments: [],
message: '留下你的评论吧。。。',
Expand All @@ -35400,7 +35395,7 @@
}
switch (action.type) {
case 'INIT_APP':
return initApp(state, action.user_name, action.repo, action.page_id, action.server_url);
return initApp(state, action.user_name, action.repo, action.page_id, action.server_url, action.ssl);
case 'LOAD_COMMENTS':
var ret = {};
_jquery2.default.ajax({
Expand All @@ -35411,7 +35406,7 @@
xhrFields: {
withCredentials: true
},
url: 'http://' + state.get('meta').get('server_url') + '/comments?page_id=' + action.page_id + '&user_name=' + action.user_name + '&repo=' + action.repo
url: (state.get('meta').get('ssl') ? "https" : "http") + '://' + state.get('meta').get('server_url') + '/comments?page_id=' + action.page_id + '&user_name=' + action.user_name + '&repo=' + action.repo
}).done(function (data) {
ret = loadComments(state, data);
}.bind(this)).fail(function (xhr) {
Expand All @@ -35428,7 +35423,7 @@
xhrFields: {
withCredentials: true
},
url: 'http://' + state.get('meta').get('server_url') + '/users/auth'
url: (state.get('meta').get('ssl') ? "https" : "http") + '://' + state.get('meta').get('server_url') + '/users/auth'
}).done(function (data) {
ret = authRequest(state, data);
}.bind(this)).fail(function (xhr) {
Expand All @@ -35447,7 +35442,7 @@
withCredentials: true
},
data: JSON.stringify({ body: action.text, page_id: state.get('meta').get('page_id'), repo: state.get('meta').get('repo'), user_name: state.get('meta').get('user_name') }),
url: 'http://' + state.get('meta').get('server_url') + '/comments'
url: (state.get('meta').get('ssl') ? "https" : "http") + '://' + state.get('meta').get('server_url') + '/comments'
}).done(function (data) {
ret = createComment(state, data);
}.bind(this)).fail(function (xhr) {
Expand All @@ -35467,8 +35462,8 @@
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// 初始化应用元数据
function initApp(state, user_name, repo, page_id, server_url) {
return state.mergeDeep((0, _immutable.fromJS)({ meta: { user_name: user_name, repo: repo, page_id: page_id, server_url: server_url } }));
function initApp(state, user_name, repo, page_id, server_url, ssl) {
return state.mergeDeep((0, _immutable.fromJS)({ meta: { user_name: user_name, repo: repo, page_id: page_id, server_url: server_url, ssl: ssl } }));
}

// 加载评论列表
Expand Down
2 changes: 1 addition & 1 deletion client/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script defer="true" src="./bundle.js"
id="github-comment" data-username="teddy-ma"
data-repo="sliders" data-page-id="1"
>
data-server-url="localhost:5000">
</script>
</div>
</body>
Expand Down
12 changes: 3 additions & 9 deletions client/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,14 @@ const user_name = script_tag.dataset.username;
const repo = script_tag.dataset.repo;
const page_id = script_tag.dataset.pageId;
const server_url = script_tag.dataset.serverUrl || 'github-comment.herokuapp.com';
const ssl = script_tag.dataset.ssl || false;
const wrapper_id = 'github-comments';

// 定义 url 接口地址
const COMMENTS_URL = `http://${server_url}/comments?page_id=${page_id}&user_name=${user_name}&repo=${repo}`;
const AUTH_URL = `http://${server_url}/users/auth`;

// 创建 store
const createStoreDevTools = compose(window.devToolsExtension
? window.devToolsExtension()
: f => f)(createStore);
const store = createStoreDevTools(reducer);
const store = createStore(reducer);

// 初始化基础信息
store.dispatch({ type: 'INIT_APP', user_name, repo, page_id, server_url });
store.dispatch({ type: 'INIT_APP', user_name, repo, page_id, server_url, ssl });
// 初始化评论列表
store.dispatch({ type: 'LOAD_COMMENTS', user_name, repo, page_id });
// 初始化登录状态
Expand Down
13 changes: 7 additions & 6 deletions client/src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {List, Map, fromJS} from 'immutable';
import $ from 'jquery';

// 初始化应用元数据
function initApp(state, user_name, repo, page_id, server_url) {
function initApp(state, user_name, repo, page_id, server_url, ssl) {
return state.mergeDeep(
fromJS({meta: {user_name: user_name, repo: repo, page_id: page_id, server_url: server_url}})
fromJS({meta: {user_name: user_name, repo: repo, page_id: page_id, server_url: server_url, ssl: ssl}})
);
}

Expand Down Expand Up @@ -45,6 +45,7 @@ export default function(state, action) {
repo: '',
page_id: '',
server_url: '',
ssl: false
},
comments: [],
message: '留下你的评论吧。。。',
Expand All @@ -66,7 +67,7 @@ export default function(state, action) {
}
switch (action.type) {
case 'INIT_APP':
return initApp(state, action.user_name, action.repo, action.page_id, action.server_url);
return initApp(state, action.user_name, action.repo, action.page_id, action.server_url, action.ssl);
case 'LOAD_COMMENTS':
var ret = {};
$.ajax({
Expand All @@ -77,7 +78,7 @@ export default function(state, action) {
xhrFields: {
withCredentials: true
},
url: `http://${state.get('meta').get('server_url')}/comments?page_id=${action.page_id}&user_name=${action.user_name}&repo=${action.repo}`,
url: `${state.get('meta').get('ssl') ? "https" : "http"}://${state.get('meta').get('server_url')}/comments?page_id=${action.page_id}&user_name=${action.user_name}&repo=${action.repo}`,
}).done(function(data) {
ret = loadComments(state, data);
}.bind(this)).fail(function(xhr) {
Expand All @@ -94,7 +95,7 @@ export default function(state, action) {
xhrFields: {
withCredentials: true
},
url: `http://${state.get('meta').get('server_url')}/users/auth`,
url: `${state.get('meta').get('ssl') ? "https" : "http"}://${state.get('meta').get('server_url')}/users/auth`,
}).done(function(data) {
ret = authRequest(state, data);
}.bind(this)).fail(function(xhr) {
Expand All @@ -113,7 +114,7 @@ export default function(state, action) {
withCredentials: true
},
data: JSON.stringify({ body: action.text, page_id: state.get('meta').get('page_id'), repo: state.get('meta').get('repo'), user_name: state.get('meta').get('user_name') }),
url: `http://${state.get('meta').get('server_url')}/comments`,
url: `${state.get('meta').get('ssl') ? "https" : "http"}://${state.get('meta').get('server_url')}/comments`,
}).done(function(data) {
ret = createComment(state, data);
}.bind(this)).fail(function(xhr) {
Expand Down

0 comments on commit 1d10cea

Please sign in to comment.