Skip to content

Commit 48592d6

Browse files
authored
Merge branch 'master' into feature/addSecrets
2 parents a8b9963 + 0bea4da commit 48592d6

62 files changed

Lines changed: 1381 additions & 1404 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.babelrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"presets": [
3+
"es2015"
4+
],
5+
"plugins": [
6+
"transform-runtime"
7+
]
8+
}

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.min.js

.eslintrc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
],
1717
"array-callback-return": "error",
1818
"arrow-body-style": "error",
19-
"arrow-parens": "error",
2019
"arrow-spacing": "error",
2120
"block-scoped-var": "off",
2221
"block-spacing": "error",
@@ -123,7 +122,7 @@
123122
"no-extend-native": "error",
124123
"no-extra-bind": "error",
125124
"no-extra-label": "error",
126-
"no-extra-parens": "error",
125+
"no-extra-parens": "warn",
127126
"no-floating-decimal": "error",
128127
"no-global-assign": "error",
129128
"no-implicit-coercion": "error",
@@ -195,7 +194,7 @@
195194
"no-unneeded-ternary": "error",
196195
"no-unsafe-negation": "error",
197196
"no-unused-expressions": "error",
198-
"no-use-before-define": "error",
197+
"no-use-before-define": "warn",
199198
"no-useless-call": "error",
200199
"no-useless-computed-key": "error",
201200
"no-useless-concat": "error",

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ backups/
1818

1919
# ignore config files
2020
config.json
21-
public/js/config.js
2221
.sequelizerc
2322

2423
# ignore webpack build

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: node_js
2+
node_js:
3+
- 6
4+
- 7
5+
- stable
6+
env:
7+
- CXX=g++-4.8
8+
addons:
9+
apt:
10+
sources:
11+
- ubuntu-toolchain-r-test
12+
packages:
13+
- g++-4.8

README.md

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
HackMD
22
===
33

4-
[![Join the chat at https://gitter.im/hackmdio/hackmd](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/hackmdio/hackmd?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4+
[![Join the chat at https://gitter.im/hackmdio/hackmd][gitter-image]][gitter-url]
5+
[![build status][travis-image]][travis-url]
6+
57

68
HackMD lets you create realtime collaborative markdown notes on all platforms.
79
Inspired by Hackpad, with more focus on speed and flexibility.
@@ -48,9 +50,9 @@ Browsers Requirement
4850
Prerequisite
4951
---
5052

51-
- Node.js 4.x or up (test up to 6.7.0)
53+
- Node.js 6.x or up (test up to 7.5.0)
5254
- Database (PostgreSQL, MySQL, MariaDB, SQLite, MSSQL) use charset `utf8`
53-
- npm
55+
- npm (and its dependencies, especially [uWebSockets](https://github.com/uWebSockets/uWebSockets#nodejs-developers), [node-gyp](https://github.com/nodejs/node-gyp#installation))
5456

5557
Get started
5658
---
@@ -59,7 +61,7 @@ Get started
5961
2. Enter the directory and type `bin/setup`, which will install npm dependencies and create configs. The setup script is written in Bash, you would need bash as a prerequisite.
6062
3. Setup the configs, see more below
6163
4. Setup environment variables which will overwrite the configs
62-
5. Build front-end bundle by `npm run build:prod` (use `npm run build:dev` if you are in development)
64+
5. Build front-end bundle by `npm run build` (use `npm run dev` if you are in development)
6365
6. Run the server as you like (node, forever, pm2)
6466

6567
Upgrade guide
@@ -70,7 +72,7 @@ If you are upgrading HackMD from an older version, follow these steps:
7072
1. Fully stop your old server first (important)
7173
2. `git pull` or do whatever that updates the files
7274
3. `npm install` to update dependencies
73-
4. Build front-end bundle by `npm run build:prod` (use `npm run build:dev` if you are in development)
75+
4. Build front-end bundle by `npm run build` (use `npm run dev` if you are in development)
7476
5. Modify the file named `.sequelizerc`, change the value of the variable `url` with your db connection string
7577
For example: `postgres://username:password@localhost:5432/hackmd`
7678
6. Run `node_modules/.bin/sequelize db:migrate`, this step will migrate your db to the latest schema
@@ -97,19 +99,9 @@ Configuration files
9799
There are some configs you need to change in the files below
98100

99101
```
100-
./config.json --- for server settings
101-
./public/js/config.js --- for client settings
102+
./config.json ----application settings
102103
```
103104

104-
Client settings `config.js`
105-
---
106-
107-
| variables | example values | description |
108-
| --------- | ------ | ----------- |
109-
| debug | `true` or `false` | set debug mode, show more logs |
110-
| domain | `localhost` | domain name |
111-
| urlpath | `hackmd` | sub url path, like: `www.example.com/<urlpath>` |
112-
113105
Environment variables (will overwrite other server configs)
114106
---
115107

@@ -126,6 +118,7 @@ Environment variables (will overwrite other server configs)
126118
| HMD_USECDN | `true` or `false` | set to use CDN resources or not (default is `true`) |
127119
| HMD_ALLOW_ANONYMOUS | `true` or `false` | set to allow anonymous usage (default is `true`) |
128120
| HMD_ALLOW_FREEURL | `true` or `false` | set to allow new note by accessing not exist note url |
121+
| HMD_DEFAULT_PERMISSION | `freely`, `editable`, `limited`, `locked` or `private` | set notes default permission (only applied on signed users) |
129122
| HMD_DB_URL | `mysql://localhost:3306/database` | set the db url |
130123
| HMD_FACEBOOK_CLIENTID | no example | Facebook API client id |
131124
| HMD_FACEBOOK_CLIENTSECRET | no example | Facebook API client secret |
@@ -140,15 +133,15 @@ Environment variables (will overwrite other server configs)
140133
| HMD_DROPBOX_CLIENTSECRET | no example | Dropbox API client secret |
141134
| HMD_GOOGLE_CLIENTID | no example | Google API client id |
142135
| HMD_GOOGLE_CLIENTSECRET | no example | Google API client secret |
143-
| HMD_LDAP_URL | ldap://example.com | url of LDAP server |
136+
| HMD_LDAP_URL | `ldap://example.com` | url of LDAP server |
144137
| HMD_LDAP_BINDDN | no example | bindDn for LDAP access |
145138
| HMD_LDAP_BINDCREDENTIALS | no example | bindCredentials for LDAP access |
146-
| HMD_LDAP_TOKENSECRET | supersecretkey | secret used for generating access/refresh tokens |
147-
| HMD_LDAP_SEARCHBASE | o=users,dc=example,dc=com | LDAP directory to begin search from |
148-
| HMD_LDAP_SEARCHFILTER | (uid={{username}}) | LDAP filter to search with |
139+
| HMD_LDAP_TOKENSECRET | `supersecretkey` | secret used for generating access/refresh tokens |
140+
| HMD_LDAP_SEARCHBASE | `o=users,dc=example,dc=com` | LDAP directory to begin search from |
141+
| HMD_LDAP_SEARCHFILTER | `(uid={{username}})` | LDAP filter to search with |
149142
| HMD_LDAP_SEARCHATTRIBUTES | no example | LDAP attributes to search with |
150-
| HMD_LDAP_TLS_CA | no example | Root CA for LDAP TLS in PEM format |
151-
| HMD_LDAP_PROVIDERNAME | My institution | Optional name to be displayed at login form indicating the LDAP provider |
143+
| HMD_LDAP_TLS_CA | `server-cert.pem, root.pem` | Root CA for LDAP TLS in PEM format (use comma to separate) |
144+
| HMD_LDAP_PROVIDERNAME | `My institution` | Optional name to be displayed at login form indicating the LDAP provider |
152145
| HMD_IMGUR_CLIENTID | no example | Imgur API client id |
153146
| HMD_EMAIL | `true` or `false` | set to allow email signin |
154147
| HMD_ALLOW_EMAIL_REGISTER | `true` or `false` | set to allow email register (only applied when email is set, default is `true`) |
@@ -158,7 +151,7 @@ Environment variables (will overwrite other server configs)
158151
| HMD_S3_REGION | `ap-northeast-1` | AWS S3 region |
159152
| HMD_S3_BUCKET | no example | AWS S3 bucket name |
160153

161-
Server settings `config.json`
154+
Application settings `config.json`
162155
---
163156

164157
| variables | example values | description |
@@ -174,6 +167,7 @@ Server settings `config.json`
174167
| usecdn | `true` or `false` | set to use CDN resources or not (default is `true`) |
175168
| allowanonymous | `true` or `false` | set to allow anonymous usage (default is `true`) |
176169
| allowfreeurl | `true` or `false` | set to allow new note by accessing not exist note url |
170+
| defaultpermission | `freely`, `editable`, `limited`, `locked` or `private` | set notes default permission (only applied on signed users) |
177171
| dburl | `mysql://localhost:3306/database` | set the db url, if set this variable then below db config won't be applied |
178172
| db | `{ "dialect": "sqlite", "storage": "./db.hackmd.sqlite" }` | set the db configs, [see more here](http://sequelize.readthedocs.org/en/latest/api/sequelize/) |
179173
| sslkeypath | `./cert/client.key` | ssl key path (only need when you set usessl) |
@@ -207,7 +201,7 @@ Third-party integration api key settings
207201
| ------- | --------- | ----------- |
208202
| facebook, twitter, github, gitlab, dropbox, google, ldap | environment variables or `config.json` | for signin |
209203
| imgur | environment variables or `config.json` | for image upload |
210-
| google drive, dropbox | `public/js/config.js` | for export and import |
204+
| google drive(`google/apiKey`, `google/clientID`), dropbox(`dropbox/appKey`) | `config.json` | for export and import |
211205

212206
Third-party integration oauth callback urls
213207
---
@@ -230,3 +224,7 @@ Additionally, now can show other clients' selections.
230224
See more at [http://operational-transformation.github.io/](http://operational-transformation.github.io/)
231225

232226
**License under MIT.**
227+
[gitter-image]: https://badges.gitter.im/Join%20Chat.svg
228+
[gitter-url]: https://gitter.im/hackmdio/hackmd?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
229+
[travis-image]: https://travis-ci.org/hackmdio/hackmd.svg?branch=master
230+
[travis-url]: https://travis-ci.org/hackmdio/hackmd

app.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ var validator = require('validator');
2626
var config = require("./lib/config.js");
2727
var logger = require("./lib/logger.js");
2828
var auth = require("./lib/auth.js");
29-
var history = require("./lib/history.js");
3029
var response = require("./lib/response.js");
3130
var models = require("./lib/models");
3231

@@ -443,6 +442,7 @@ app.get('/logout', function (req, res) {
443442
req.logout();
444443
res.redirect(config.serverurl + '/');
445444
});
445+
var history = require("./lib/history.js");
446446
//get history
447447
app.get('/history', history.historyGet);
448448
//post history
@@ -502,7 +502,7 @@ app.post('/uploadimage', function (req, res) {
502502
switch (config.imageUploadType) {
503503
case 'filesystem':
504504
res.send({
505-
link: url.resolve(config.serverurl, files.image.path.match(/^public(.+$)/)[1])
505+
link: url.resolve(config.serverurl + '/', files.image.path.match(/^public\/(.+$)/)[1])
506506
});
507507

508508
break;
@@ -608,7 +608,7 @@ function startListen() {
608608
// sync db then start listen
609609
models.sequelize.sync().then(function () {
610610
// check if realtime is ready
611-
if (history.isReady() && realtime.isReady()) {
611+
if (realtime.isReady()) {
612612
models.Revision.checkAllNotesRevision(function (err, notes) {
613613
if (err) throw new Error(err);
614614
if (!notes || notes.length <= 0) return startListen();
@@ -639,7 +639,7 @@ function handleTermSignals() {
639639
}, 0);
640640
});
641641
var checkCleanTimer = setInterval(function () {
642-
if (history.isReady() && realtime.isReady()) {
642+
if (realtime.isReady()) {
643643
models.Revision.checkAllNotesRevision(function (err, notes) {
644644
if (err) return logger.error(err);
645645
if (!notes || notes.length <= 0) {

bin/heroku

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ EOF
2828
2929
EOF
3030

31-
cp public/js/config.js.example public/js/config.js
32-
3331
# build app
34-
npm run build:prod
32+
npm run build
3533
fi

bin/setup

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
set -e
4+
35
# run command at repo root
46
CURRENT_PATH=$PWD
57
if [ -d .git ]; then
@@ -21,10 +23,6 @@ if [ ! -f config.json ]; then
2123
cp config.json.example config.json
2224
fi
2325

24-
if [ ! -f publis/js/config.js ]; then
25-
cp public/js/config.js.example public/js/config.js
26-
fi
27-
2826
if [ ! -f .sequelizerc ]; then
2927
cp .sequelizerc.example .sequelizerc
3028
fi

config.json.example

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22
"test": {
33
"db": {
44
"dialect": "sqlite",
5-
"storage": "./db.hackmd.sqlite"
5+
"storage": ":memory:"
66
}
77
},
88
"development": {
9-
"domain": "localhost",
109
"db": {
11-
"username": "",
12-
"password": "",
13-
"database": "hackmd",
14-
"host": "localhost",
15-
"port": "3306",
16-
"dialect": "mysql"
10+
"dialect": "sqlite",
11+
"storage": "./db.hackmd.sqlite"
1712
}
1813
},
1914
"production": {
@@ -45,11 +40,13 @@
4540
},
4641
"dropbox": {
4742
"clientID": "change this",
48-
"clientSecret": "change this"
43+
"clientSecret": "change this",
44+
"appKey": "change this"
4945
},
5046
"google": {
5147
"clientID": "change this",
52-
"clientSecret": "change this"
48+
"clientSecret": "change this",
49+
"apiKey": "change this"
5350
},
5451
"ldap": {
5552
"url": "ldap://change_this",

0 commit comments

Comments
 (0)