From c2a8911b9c7872ea0d085020aa17e82162130f3d Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Fri, 13 Jan 2017 22:46:38 +0800 Subject: [PATCH 1/9] Move config variable to lib/config --- public/js/common.js | 25 +------------------------ public/js/lib/config/index.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 24 deletions(-) create mode 100644 public/js/lib/config/index.js diff --git a/public/js/common.js b/public/js/common.js index 6d54b4506..9a60122b3 100644 --- a/public/js/common.js +++ b/public/js/common.js @@ -1,21 +1,4 @@ -// import config from './config'; - -import { - domain, // domain name - urlpath, // sub url path, like: www.example.com/ - debug, - GOOGLE_API_KEY, - GOOGLE_CLIENT_ID, - DROPBOX_APP_KEY -} from './config'; - -//common -export const port = window.location.port; -window.serverurl = `${window.location.protocol}//${domain ? domain : window.location.hostname}${port ? ':' + port : ''}${urlpath ? '/' + urlpath : ''}`; -export const noteid = urlpath ? window.location.pathname.slice(urlpath.length + 1, window.location.pathname.length).split('/')[1] : window.location.pathname.split('/')[1]; -export const noteurl = `${serverurl}/${noteid}`; - -export const version = '0.5.0'; +import { serverurl } from './lib/config'; let checkAuth = false; let profile = null; @@ -101,12 +84,6 @@ export function checkIfAuth(yesCallback, noCallback) { } export default { - domain, - urlpath, - debug, - GOOGLE_API_KEY, - GOOGLE_CLIENT_ID, - DROPBOX_APP_KEY, checkAuth, profile, lastLoginState, diff --git a/public/js/lib/config/index.js b/public/js/lib/config/index.js new file mode 100644 index 000000000..bffbadd9d --- /dev/null +++ b/public/js/lib/config/index.js @@ -0,0 +1,19 @@ +import configJson from '../../../../config.json'; // root path json config + +const config = 'production' === process.env.NODE_ENV ? configJson.production : configJson.development; + +export const GOOGLE_API_KEY = config.google && config.google.apiKey; +export const GOOGLE_CLIENT_ID = config.google && config.google.clientID +export const DROPBOX_APP_KEY = config.dropbox && config.dropbox.appKey + +export const domain = config.domain; +export const urlpath = config.urlpath; +export const debug = config.debug; + +export const port = window.location.port; +export const serverurl = `${window.location.protocol}//${domain ? domain : window.location.hostname}${port ? ':' + port : ''}${urlpath ? '/' + urlpath : ''}`; +window.serverurl = serverurl; +export const noteid = urlpath ? window.location.pathname.slice(urlpath.length + 1, window.location.pathname.length).split('/')[1] : window.location.pathname.split('/')[1]; +export const noteurl = `${serverurl}/${noteid}`; + +export const version = '0.5.0'; From 0fca629c34b83617b2d72e42aa0edb66fd2e71f6 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Fri, 13 Jan 2017 22:51:44 +0800 Subject: [PATCH 2/9] Rename common.js to login.js --- public/js/cover.js | 2 +- public/js/extra.js | 2 +- public/js/history.js | 8 ++++++-- public/js/index.js | 7 +++++-- public/js/{common.js => lib/common/login.js} | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) rename public/js/{common.js => lib/common/login.js} (98%) diff --git a/public/js/cover.js b/public/js/cover.js index 677d82eb6..bc04923b3 100644 --- a/public/js/cover.js +++ b/public/js/cover.js @@ -9,7 +9,7 @@ import { getLoginState, resetCheckAuth, setloginStateChangeEvent -} from './common'; +} from './lib/common/login'; import { clearDuplicatedHistory, diff --git a/public/js/extra.js b/public/js/extra.js index 6cfb5b0ad..b651d9e6c 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -11,7 +11,7 @@ import PDFObject from 'pdfobject'; import S from 'string'; import { saveAs } from 'file-saver'; -require('./common'); +require('./lib/common/login'); require('../vendor/md-toc'); var Viz = require("viz.js"); diff --git a/public/js/history.js b/public/js/history.js index f12016837..34b2cba74 100644 --- a/public/js/history.js +++ b/public/js/history.js @@ -1,9 +1,13 @@ import store from 'store'; import S from 'string'; + +import { + checkIfAuth +} from './lib/common/login'; + import { - checkIfAuth, urlpath -} from './common'; +} from './lib/config'; window.migrateHistoryFromTempCallback = null; diff --git a/public/js/index.js b/public/js/index.js index 660f73e45..3bf42ad43 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -19,7 +19,10 @@ var List = require('list.js'); import { checkLoginStateChanged, - setloginStateChangeEvent, + setloginStateChangeEvent +} from './lib/common/login'; + +import { debug, DROPBOX_APP_KEY, GOOGLE_API_KEY, @@ -28,7 +31,7 @@ import { noteurl, urlpath, version -} from './common'; +} from './lib/config'; import { autoLinkify, diff --git a/public/js/common.js b/public/js/lib/common/login.js similarity index 98% rename from public/js/common.js rename to public/js/lib/common/login.js index 9a60122b3..12cc41fc4 100644 --- a/public/js/common.js +++ b/public/js/lib/common/login.js @@ -1,4 +1,4 @@ -import { serverurl } from './lib/config'; +import { serverurl } from '../config'; let checkAuth = false; let profile = null; From 2408ff4ba96c929a575b34e85d5cff0a01789ca4 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Fri, 13 Jan 2017 23:12:17 +0800 Subject: [PATCH 3/9] Add default value for config --- public/js/lib/config/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/public/js/lib/config/index.js b/public/js/lib/config/index.js index bffbadd9d..2b73679fa 100644 --- a/public/js/lib/config/index.js +++ b/public/js/lib/config/index.js @@ -2,13 +2,13 @@ import configJson from '../../../../config.json'; // root path json config const config = 'production' === process.env.NODE_ENV ? configJson.production : configJson.development; -export const GOOGLE_API_KEY = config.google && config.google.apiKey; -export const GOOGLE_CLIENT_ID = config.google && config.google.clientID -export const DROPBOX_APP_KEY = config.dropbox && config.dropbox.appKey +export const GOOGLE_API_KEY = (config.google && config.google.apiKey) || ''; +export const GOOGLE_CLIENT_ID = (config.google && config.google.clientID) || ''; +export const DROPBOX_APP_KEY = (config.dropbox && config.dropbox.appKey) || ''; -export const domain = config.domain; -export const urlpath = config.urlpath; -export const debug = config.debug; +export const domain = config.domain || ''; // domain name +export const urlpath = config.urlpath || ''; // sub url path, like: www.example.com/ +export const debug = config.debug || false; export const port = window.location.port; export const serverurl = `${window.location.protocol}//${domain ? domain : window.location.hostname}${port ? ':' + port : ''}${urlpath ? '/' + urlpath : ''}`; From a541569d7edbe827cae69c666079d5d1ded6790c Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Fri, 13 Jan 2017 23:12:27 +0800 Subject: [PATCH 4/9] Remove old config.js.example --- public/js/config.js.example | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 public/js/config.js.example diff --git a/public/js/config.js.example b/public/js/config.js.example deleted file mode 100644 index c5de388f6..000000000 --- a/public/js/config.js.example +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - domain: '', // domain name - urlpath: '', // sub url path, like: www.example.com/ - - // settings - debug: false, - - GOOGLE_API_KEY: '', - GOOGLE_CLIENT_ID: '', - DROPBOX_APP_KEY: '' -}; From 1ed19966394b9735c348ec0116ec0e939c363ce6 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Fri, 13 Jan 2017 23:37:16 +0800 Subject: [PATCH 5/9] Remove config.js from setup files --- .gitignore | 1 - bin/heroku | 2 -- bin/setup | 4 ---- 3 files changed, 7 deletions(-) diff --git a/.gitignore b/.gitignore index f48b3c6f5..ab83c145f 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,6 @@ backups/ # ignore config files config.json -public/js/config.js .sequelizerc # ignore webpack build diff --git a/bin/heroku b/bin/heroku index e80100380..1228b2835 100755 --- a/bin/heroku +++ b/bin/heroku @@ -28,8 +28,6 @@ EOF EOF - cp public/js/config.js.example public/js/config.js - # build app npm run build fi diff --git a/bin/setup b/bin/setup index e24d4de72..6724b2d54 100755 --- a/bin/setup +++ b/bin/setup @@ -21,10 +21,6 @@ if [ ! -f config.json ]; then cp config.json.example config.json fi -if [ ! -f publis/js/config.js ]; then - cp public/js/config.js.example public/js/config.js -fi - if [ ! -f .sequelizerc ]; then cp .sequelizerc.example .sequelizerc fi From b4bed37d64d59a70db3f0373894cf6ac611c1630 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sat, 14 Jan 2017 14:17:20 +0800 Subject: [PATCH 6/9] Add google apiKey & dropbox appKey to config.json --- config.json.example | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config.json.example b/config.json.example index e5e3fc56c..e980566fc 100644 --- a/config.json.example +++ b/config.json.example @@ -45,11 +45,13 @@ }, "dropbox": { "clientID": "change this", - "clientSecret": "change this" + "clientSecret": "change this", + "appKey": "change this" }, "google": { "clientID": "change this", - "clientSecret": "change this" + "clientSecret": "change this", + "apiKey": "change this" }, "imgur": { "clientID": "change this" From 98c0cfc6a7dbf19a7996ff37968605ec946c97e1 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sat, 14 Jan 2017 15:24:31 +0800 Subject: [PATCH 7/9] Update README --- README.md | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index cc05872db..f6532d5e6 100644 --- a/README.md +++ b/README.md @@ -97,19 +97,9 @@ Configuration files There are some configs you need to change in the files below ``` -./config.json --- for server settings -./public/js/config.js --- for client settings +./config.json ----application settings ``` -Client settings `config.js` ---- - -| variables | example values | description | -| --------- | ------ | ----------- | -| debug | `true` or `false` | set debug mode, show more logs | -| domain | `localhost` | domain name | -| urlpath | `hackmd` | sub url path, like: `www.example.com/` | - Environment variables (will overwrite other server configs) --- @@ -148,7 +138,7 @@ Environment variables (will overwrite other server configs) | HMD_S3_REGION | `ap-northeast-1` | AWS S3 region | | HMD_S3_BUCKET | no example | AWS S3 bucket name | -Server settings `config.json` +Application settings `config.json` --- | variables | example values | description | @@ -196,7 +186,7 @@ Third-party integration api key settings | ------- | --------- | ----------- | | facebook, twitter, github, gitlab, dropbox, google | environment variables or `config.json` | for signin | | imgur | environment variables or `config.json` | for image upload | -| google drive, dropbox | `public/js/config.js` | for export and import | +| google drive(`google/apiKey`, `google/clientID`), dropbox(`dropbox/appKey`) | `config.json` | for export and import | Third-party integration oauth callback urls --- From 04292240d6a589c537afb8e9838dcc0f062d0f2c Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sat, 14 Jan 2017 15:47:13 +0800 Subject: [PATCH 8/9] Minor style update --- .eslintrc | 5 ++--- public/js/lib/common/login.js | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.eslintrc b/.eslintrc index 53a6dcb0b..bd14731c6 100644 --- a/.eslintrc +++ b/.eslintrc @@ -16,7 +16,6 @@ ], "array-callback-return": "error", "arrow-body-style": "error", - "arrow-parens": "error", "arrow-spacing": "error", "block-scoped-var": "off", "block-spacing": "error", @@ -123,7 +122,7 @@ "no-extend-native": "error", "no-extra-bind": "error", "no-extra-label": "error", - "no-extra-parens": "error", + "no-extra-parens": "warn", "no-floating-decimal": "error", "no-global-assign": "error", "no-implicit-coercion": "error", @@ -195,7 +194,7 @@ "no-unneeded-ternary": "error", "no-unsafe-negation": "error", "no-unused-expressions": "error", - "no-use-before-define": "error", + "no-use-before-define": "warn", "no-useless-call": "error", "no-useless-computed-key": "error", "no-useless-concat": "error", diff --git a/public/js/lib/common/login.js b/public/js/lib/common/login.js index 12cc41fc4..f1a03c72f 100644 --- a/public/js/lib/common/login.js +++ b/public/js/lib/common/login.js @@ -32,7 +32,7 @@ export function setLoginState(bool, id) { export function checkLoginStateChanged() { if (getLoginState() != lastLoginState || getUserId() != lastUserId) { - if(loginStateChangeEvent) { + if (loginStateChangeEvent) { loginStateChangeEvent(); } return true; From 0f833f099f61b93e76a5f32175580fc2c0b9dc1a Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sat, 14 Jan 2017 19:05:54 +0800 Subject: [PATCH 9/9] Update server google/dropbox config check --- lib/config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/config.js b/lib/config.js index 53497f1f8..c0a7fffe2 100644 --- a/lib/config.js +++ b/lib/config.js @@ -90,11 +90,11 @@ var gitlab = (process.env.HMD_GITLAB_CLIENTID && process.env.HMD_GITLAB_CLIENTSE var dropbox = (process.env.HMD_DROPBOX_CLIENTID && process.env.HMD_DROPBOX_CLIENTSECRET) ? { clientID: process.env.HMD_DROPBOX_CLIENTID, clientSecret: process.env.HMD_DROPBOX_CLIENTSECRET -} : config.dropbox || false; +} : (config.dropbox && config.dropbox.clientID && config.dropbox.clientSecret) || false; var google = (process.env.HMD_GOOGLE_CLIENTID && process.env.HMD_GOOGLE_CLIENTSECRET) ? { clientID: process.env.HMD_GOOGLE_CLIENTID, clientSecret: process.env.HMD_GOOGLE_CLIENTSECRET -} : config.google || false; +} : (config.google && config.google.clientID && config.google.clientSecret) || false; var imgur = process.env.HMD_IMGUR_CLIENTID || config.imgur || false; var email = process.env.HMD_EMAIL ? (process.env.HMD_EMAIL === 'true') : !!config.email;