2016-01-19 11:21:45 -05:00
HackMD
2015-05-04 03:53:29 -04:00
===
2017-03-14 11:30:35 -04:00
[![Standard - JavaScript Style Guide][standardjs-image]][standardjs-url]
2017-03-13 06:42:22 -04:00
2017-02-15 05:14:58 -05:00
[![Join the chat at https://gitter.im/hackmdio/hackmd][gitter-image]][gitter-url]
[![build status][travis-image]][travis-url]
2017-10-08 07:15:29 -04:00
[![version][github-version-badge]][github-release-page]
2017-02-15 05:14:58 -05:00
2015-08-15 00:15:42 -04:00
2017-10-29 06:16:40 -04:00
HackMD lets you create realtime collaborative markdown notes on all platforms.
Inspired by Hackpad, with more focus on speed and flexibility.
2016-10-02 22:33:30 -04:00
Still in the early stage, feel free to fork or contribute to HackMD.
2015-05-04 03:53:29 -04:00
2016-10-02 22:33:30 -04:00
Thanks for using! :smile:
2015-05-15 00:58:13 -04:00
2017-10-13 04:04:49 -04:00
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE - RUN doctoc TO UPDATE -->
2017-10-13 03:59:57 -04:00
# Table of Contents
- [Browsers Requirement ](#browsers-requirement )
- [Installation ](#installation )
- [Getting started (Native install) ](#getting-started-native-install )
- [Prerequisite ](#prerequisite )
- [Instructions ](#instructions )
- [Heroku Deployment ](#heroku-deployment )
- [HackMD by docker container ](#hackmd-by-docker-container )
- [Upgrade ](#upgrade )
- [Native setup ](#native-setup )
- [Configuration ](#configuration )
- [Environment variables (will overwrite other server configs) ](#environment-variables-will-overwrite-other-server-configs )
- [Application settings `config.json` ](#application-settings-configjson )
- [Third-party integration api key settings ](#third-party-integration-api-key-settings )
- [Third-party integration oauth callback urls ](#third-party-integration-oauth-callback-urls )
- [Developer Notes ](#developer-notes )
- [Structure ](#structure )
- [Operational Transformation ](#operational-transformation )
- [License ](#license )
2017-10-13 04:04:49 -04:00
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2017-10-08 07:37:20 -04:00
# Browsers Requirement
2016-10-04 04:41:26 -04:00
2016-10-31 03:32:36 -04:00
- Chrome >= 47, Chrome for Android >= 47
2016-01-29 14:28:45 -05:00
- Safari >= 9, iOS Safari >= 8.4
- Firefox >= 44
- IE >= 9, Edge >= 12
- Opera >= 34, Opera Mini not supported
- Android Browser >= 4.4
2017-10-08 07:37:20 -04:00
# Installation
## Getting started (Native install)
### Prerequisite
2016-10-04 04:41:26 -04:00
2017-02-15 09:09:09 -05:00
- Node.js 6.x or up (test up to 7.5.0)
2016-10-15 12:53:33 -04:00
- Database (PostgreSQL, MySQL, MariaDB, SQLite, MSSQL) use charset `utf8`
2017-02-08 01:30:31 -05:00
- npm (and its dependencies, especially [uWebSockets ](https://github.com/uWebSockets/uWebSockets#nodejs-developers ), [node-gyp ](https://github.com/nodejs/node-gyp#installation ))
2015-07-11 00:52:04 -04:00
2017-10-08 07:37:20 -04:00
### Instructions
2016-10-04 04:41:26 -04:00
2015-09-27 02:45:21 -04:00
1. Download a release and unzip or clone into a directory
2016-12-10 21:31:51 -05:00
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.
2016-10-02 22:33:30 -04:00
3. Setup the configs, see more below
4. Setup environment variables which will overwrite the configs
2017-01-04 01:27:38 -05:00
5. Build front-end bundle by `npm run build` (use `npm run dev` if you are in development)
2016-10-15 02:35:31 -04:00
6. Run the server as you like (node, forever, pm2)
2015-06-01 06:04:25 -04:00
2017-10-08 07:37:20 -04:00
## Heroku Deployment
You can quickly setup a sample heroku hackmd application by clicking the button below.
[![Deploy ](https://www.herokucdn.com/deploy/button.svg )](https://heroku.com/deploy)
## HackMD by docker container
2017-10-27 23:06:43 -04:00
[![Try in PWD ](https://cdn.rawgit.com/play-with-docker/stacks/cff22438/assets/images/button.png )](http://play-with-docker.com?stack=https://github.com/hackmdio/docker-hackmd/raw/master/docker-compose.yml& stack_name=hackmd)
2017-10-08 07:37:20 -04:00
2017-10-27 23:06:43 -04:00
**Debian-based version:**
[![latest ](https://images.microbadger.com/badges/version/hackmdio/hackmd.svg )](https://microbadger.com/images/hackmdio/hackmd "Get your own version badge on microbadger.com") [![ ](https://images.microbadger.com/badges/image/hackmdio/hackmd.svg )](https://microbadger.com/images/hackmdio/hackmd "Get your own image badge on microbadger.com")
**Alpine-based version:**
[![latest-alpine ](https://images.microbadger.com/badges/version/hackmdio/hackmd:latest-alpine.svg )](https://microbadger.com/images/hackmdio/hackmd:latest-alpine "Get your own version badge on microbadger.com") [![ ](https://images.microbadger.com/badges/image/hackmdio/hackmd:latest-alpine.svg )](https://microbadger.com/images/hackmdio/hackmd:latest-alpine "Get your own image badge on microbadger.com")
The easiest way to setup HackMD using docker are using the following three commands:
```console
git clone https://github.com/hackmdio/docker-hackmd.git
cd docker-hackmd
docker-compose up
```
Read more about it in the [docker repository… ](https://github.com/hackmdio/docker-hackmd )
2017-10-08 07:37:20 -04:00
# Upgrade
## Native setup
2016-10-04 04:41:26 -04:00
2016-06-14 15:30:19 -04:00
If you are upgrading HackMD from an older version, follow these steps:
2016-06-14 10:57:54 -04:00
2016-10-02 22:33:30 -04:00
1. Fully stop your old server first (important)
2. `git pull` or do whatever that updates the files
2016-12-10 21:31:51 -05:00
3. `npm install` to update dependencies
2017-01-14 02:27:24 -05:00
4. Build front-end bundle by `npm run build` (use `npm run dev` if you are in development)
2016-12-11 10:24:04 -05:00
5. Modify the file named `.sequelizerc` , change the value of the variable `url` with your db connection string
2016-10-02 22:33:30 -04:00
For example: `postgres://username:password@localhost:5432/hackmd`
2016-12-11 10:24:04 -05:00
6. Run `node_modules/.bin/sequelize db:migrate` , this step will migrate your db to the latest schema
7. Start your whole new server!
2016-06-01 12:13:01 -04:00
2017-10-08 07:37:20 -04:00
* [migration-to-0.5.0 ](https://github.com/hackmdio/migration-to-0.5.0 )
2016-10-04 04:41:26 -04:00
2017-10-29 06:16:40 -04:00
We don't use LZString to compress socket.io data and DB data after version 0.5.0.
2017-10-08 07:37:20 -04:00
Please run the migration tool if you're upgrading from the old version.
* [migration-to-0.4.0 ](https://github.com/hackmdio/migration-to-0.4.0 )
2017-10-29 06:16:40 -04:00
We've dropped MongoDB after version 0.4.0.
So here is the migration tool for you to transfer the old DB data to the new DB.
2017-10-08 07:37:20 -04:00
This tool is also used for official service.
2015-07-01 12:10:20 -04:00
2017-10-08 07:37:20 -04:00
# Configuration
2016-10-04 04:41:26 -04:00
2016-10-02 22:33:30 -04:00
There are some configs you need to change in the files below
2016-10-04 04:41:26 -04:00
2015-05-15 00:58:13 -04:00
```
2017-01-14 02:24:31 -05:00
./config.json ----application settings
2015-05-15 00:58:13 -04:00
```
2017-10-08 07:37:20 -04:00
## Environment variables (will overwrite other server configs)
2016-10-04 04:41:26 -04:00
2015-09-15 04:08:50 -04:00
| variables | example values | description |
| --------- | ------ | ----------- |
2016-10-02 22:33:30 -04:00
| NODE_ENV | `production` or `development` | set current environment (will apply corresponding settings in the `config.json` ) |
2016-04-20 06:03:55 -04:00
| DEBUG | `true` or `false` | set debug mode, show more logs |
2016-10-10 09:16:58 -04:00
| HMD_DOMAIN | `hackmd.io` | domain name |
| HMD_URL_PATH | `hackmd` | sub url path, like `www.example.com/<URL_PATH>` |
| HMD_PORT | `80` | web app port |
| HMD_ALLOW_ORIGIN | `localhost, hackmd.io` | domain name whitelist (use comma to separate) |
| HMD_PROTOCOL_USESSL | `true` or `false` | set to use ssl protocol for resources path (only applied when domain is set) |
| HMD_URL_ADDPORT | `true` or `false` | set to add port on callback url (port 80 or 443 won't applied) (only applied when domain is set) |
2016-10-23 10:27:02 -04:00
| HMD_USECDN | `true` or `false` | set to use CDN resources or not (default is `true` ) |
2016-12-21 08:36:54 -05:00
| HMD_ALLOW_ANONYMOUS | `true` or `false` | set to allow anonymous usage (default is `true` ) |
2016-12-16 02:38:05 -05:00
| HMD_ALLOW_FREEURL | `true` or `false` | set to allow new note by accessing not exist note url |
2017-02-09 21:49:45 -05:00
| HMD_DEFAULT_PERMISSION | `freely` , `editable` , `limited` , `locked` or `private` | set notes default permission (only applied on signed users) |
2016-12-22 08:20:43 -05:00
| HMD_DB_URL | `mysql://localhost:3306/database` | set the db url |
2016-10-10 09:16:58 -04:00
| HMD_FACEBOOK_CLIENTID | no example | Facebook API client id |
| HMD_FACEBOOK_CLIENTSECRET | no example | Facebook API client secret |
| HMD_TWITTER_CONSUMERKEY | no example | Twitter API consumer key |
| HMD_TWITTER_CONSUMERSECRET | no example | Twitter API consumer secret |
| HMD_GITHUB_CLIENTID | no example | GitHub API client id |
| HMD_GITHUB_CLIENTSECRET | no example | GitHub API client secret |
2017-03-14 06:04:23 -04:00
| HMD_GITLAB_SCOPE | `read_user` or `api` | GitLab API requested scope (default is `api` ) (gitlab snippet import/export need `api` scope) |
2016-10-10 09:16:58 -04:00
| HMD_GITLAB_BASEURL | no example | GitLab authentication endpoint, set to use other endpoint than GitLab.com (optional) |
| HMD_GITLAB_CLIENTID | no example | GitLab API client id |
| HMD_GITLAB_CLIENTSECRET | no example | GitLab API client secret |
2017-10-29 06:16:40 -04:00
| HMD_MATTERMOST_BASEURL | no example | Mattermost authentication endpoint |
| HMD_MATTERMOST_CLIENTID | no example | Mattermost API client id |
| HMD_MATTERMOST_CLIENTSECRET | no example | Mattermost API client secret |
2016-10-10 09:16:58 -04:00
| HMD_DROPBOX_CLIENTID | no example | Dropbox API client id |
| HMD_DROPBOX_CLIENTSECRET | no example | Dropbox API client secret |
| HMD_GOOGLE_CLIENTID | no example | Google API client id |
| HMD_GOOGLE_CLIENTSECRET | no example | Google API client secret |
2017-02-07 08:17:05 -05:00
| HMD_LDAP_URL | `ldap://example.com` | url of LDAP server |
2016-12-13 16:31:35 -05:00
| HMD_LDAP_BINDDN | no example | bindDn for LDAP access |
| HMD_LDAP_BINDCREDENTIALS | no example | bindCredentials for LDAP access |
2017-02-07 08:17:05 -05:00
| HMD_LDAP_TOKENSECRET | `supersecretkey` | secret used for generating access/refresh tokens |
| HMD_LDAP_SEARCHBASE | `o=users,dc=example,dc=com` | LDAP directory to begin search from |
| HMD_LDAP_SEARCHFILTER | `(uid={{username}})` | LDAP filter to search with |
2016-12-13 16:31:35 -05:00
| HMD_LDAP_SEARCHATTRIBUTES | no example | LDAP attributes to search with |
2017-02-07 08:17:05 -05:00
| HMD_LDAP_TLS_CA | `server-cert.pem, root.pem` | Root CA for LDAP TLS in PEM format (use comma to separate) |
2017-10-25 09:50:36 -04:00
| HMD_LDAP_PROVIDERNAME | `My institution` | Optional name to be displayed at login form indicating the LDAP provider |
2016-10-10 09:16:58 -04:00
| HMD_IMGUR_CLIENTID | no example | Imgur API client id |
2017-01-11 22:25:58 -05:00
| HMD_EMAIL | `true` or `false` | set to allow email signin |
2017-10-25 09:50:36 -04:00
| HMD_ALLOW_PDF_EXPORT | `true` or `false` | Enable or disable PDF exports |
2017-01-12 11:51:40 -05:00
| HMD_ALLOW_EMAIL_REGISTER | `true` or `false` | set to allow email register (only applied when email is set, default is `true` ) |
2016-11-17 05:13:57 -05:00
| HMD_IMAGE_UPLOAD_TYPE | `imgur` , `s3` or `filesystem` | Where to upload image. For S3, see our [S3 Image Upload Guide ](docs/guides/s3-image-upload.md ) |
| HMD_S3_ACCESS_KEY_ID | no example | AWS access key id |
| HMD_S3_SECRET_ACCESS_KEY | no example | AWS secret key |
| HMD_S3_REGION | `ap-northeast-1` | AWS S3 region |
| HMD_S3_BUCKET | no example | AWS S3 bucket name |
2017-10-12 19:14:50 -04:00
| HMD_HSTS_ENABLE | ` true` | set to enable [HSTS ](https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security ) if HTTPS is also enabled (default is ` true` ) |
2017-10-12 19:15:35 -04:00
| HMD_HSTS_INCLUDE_SUBDOMAINS | `true` | set to include subdomains in HSTS (default is `true` ) |
| HMD_HSTS_MAX_AGE | `31536000` | max duration in seconds to tell clients to keep HSTS status (default is a year) |
| HMD_HSTS_PRELOAD | `true` | whether to allow preloading of the site's HSTS status (e.g. into browsers) |
2016-04-20 06:03:55 -04:00
2017-10-08 07:37:20 -04:00
## Application settings `config.json`
2016-10-04 04:41:26 -04:00
2015-09-15 04:08:50 -04:00
| variables | example values | description |
| --------- | ------ | ----------- |
| debug | `true` or `false` | set debug mode, show more logs |
2016-04-20 06:03:55 -04:00
| domain | `localhost` | domain name |
| urlpath | `hackmd` | sub url path, like `www.example.com/<urlpath>` |
| port | `80` | web app port |
2015-09-15 04:08:50 -04:00
| alloworigin | `['localhost']` | domain name whitelist |
2016-04-20 06:03:55 -04:00
| usessl | `true` or `false` | set to use ssl server (if true will auto turn on `protocolusessl` ) |
2017-10-12 19:09:04 -04:00
| hsts | `{"enable": "true", "maxAgeSeconds": "31536000", "includeSubdomains": "true", "preload": "true"}` | [HSTS ](https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security ) options to use with HTTPS (default is the example value, max age is a year) |
2016-10-10 09:16:58 -04:00
| protocolusessl | `true` or `false` | set to use ssl protocol for resources path (only applied when domain is set) |
| urladdport | `true` or `false` | set to add port on callback url (port 80 or 443 won't applied) (only applied when domain is set) |
2016-10-23 10:27:02 -04:00
| usecdn | `true` or `false` | set to use CDN resources or not (default is `true` ) |
2016-12-21 08:36:54 -05:00
| allowanonymous | `true` or `false` | set to allow anonymous usage (default is `true` ) |
2016-12-16 02:38:05 -05:00
| allowfreeurl | `true` or `false` | set to allow new note by accessing not exist note url |
2017-03-25 05:00:43 -04:00
| defaultpermission | `freely` , `editable` , `limited` , `locked` , `protected` or `private` | set notes default permission (only applied on signed users) |
2016-12-22 08:20:43 -05:00
| dburl | `mysql://localhost:3306/database` | set the db url, if set this variable then below db config won't be applied |
2016-04-20 06:03:55 -04:00
| db | `{ "dialect": "sqlite", "storage": "./db.hackmd.sqlite" }` | set the db configs, [see more here ](http://sequelize.readthedocs.org/en/latest/api/sequelize/ ) |
| sslkeypath | `./cert/client.key` | ssl key path (only need when you set usessl) |
| sslcertpath | `./cert/hackmd_io.crt` | ssl cert path (only need when you set usessl) |
| sslcapath | `['./cert/COMODORSAAddTrustCA.crt']` | ssl ca chain (only need when you set usessl) |
| dhparampath | `./cert/dhparam.pem` | ssl dhparam path (only need when you set usessl) |
| tmppath | `./tmp/` | temp directory path |
| defaultnotepath | `./public/default.md` | default note file path |
| docspath | `./public/docs` | docs directory path |
| indexpath | `./public/views/index.ejs` | index template file path |
| hackmdpath | `./public/views/hackmd.ejs` | hackmd template file path |
| errorpath | `./public/views/error.ejs` | error template file path |
| prettypath | `./public/views/pretty.ejs` | pretty template file path |
| slidepath | `./public/views/slide.hbs` | slide template file path |
2015-09-15 04:08:50 -04:00
| sessionname | `connect.sid` | cookie session name |
| sessionsecret | `secret` | cookie session secret |
| sessionlife | `14 * 24 * 60 * 60 * 1000` | cookie session life |
2016-04-20 06:03:55 -04:00
| staticcachetime | `1 * 24 * 60 * 60 * 1000` | static file cache time |
2015-09-15 04:08:50 -04:00
| heartbeatinterval | `5000` | socket.io heartbeat interval |
| heartbeattimeout | `10000` | socket.io heartbeat timeout |
| documentmaxlength | `100000` | note max length |
2017-01-11 22:25:58 -05:00
| email | `true` or `false` | set to allow email signin |
2017-01-12 11:51:40 -05:00
| allowemailregister | `true` or `false` | set to allow email register (only applied when email is set, default is `true` ) |
2016-11-17 05:13:57 -05:00
| imageUploadType | `imgur` (default), `s3` or `filesystem` | Where to upload image
2017-10-17 11:48:33 -04:00
| s3 | `{ "accessKeyId": "YOUR_S3_ACCESS_KEY_ID", "secretAccessKey": "YOUR_S3_ACCESS_KEY", "region": "YOUR_S3_REGION" }` | When `imageUploadType` be set to `s3` , you would also need to setup this key, check our [S3 Image Upload Guide ](docs/guides/s3-image-upload.md ) |
2017-09-23 12:28:57 -04:00
| s3bucket | `YOUR_S3_BUCKET_NAME` | bucket name when `imageUploadType` is set to `s3` |
2016-03-14 23:30:43 -04:00
2017-10-08 07:37:20 -04:00
## Third-party integration api key settings
2016-10-04 04:41:26 -04:00
2016-10-10 09:16:58 -04:00
| service | settings location | description |
2016-03-14 23:30:43 -04:00
| ------- | --------- | ----------- |
2017-10-29 06:16:40 -04:00
| facebook, twitter, github, gitlab, mattermost, dropbox, google, ldap | environment variables or `config.json` | for signin |
2016-10-10 09:16:58 -04:00
| imgur | environment variables or `config.json` | for image upload |
2017-01-14 02:24:31 -05:00
| google drive(`google/apiKey`, `google/clientID` ), dropbox(`dropbox/appKey`) | `config.json` | for export and import |
2016-04-23 06:58:24 -04:00
2017-10-08 07:37:20 -04:00
## Third-party integration oauth callback urls
2016-10-04 04:41:26 -04:00
2016-07-05 11:16:02 -04:00
| service | callback url (after the server url) |
| ------- | --------- |
| facebook | `/auth/facebook/callback` |
| twitter | `/auth/twitter/callback` |
| github | `/auth/github/callback` |
| gitlab | `/auth/gitlab/callback` |
2017-10-29 06:16:40 -04:00
| mattermost | `/auth/mattermost/callback` |
2016-07-05 11:16:02 -04:00
| dropbox | `/auth/dropbox/callback` |
| google | `/auth/google/callback` |
2017-10-08 07:37:20 -04:00
# Developer Notes
## Structure
```text
hackmd/
├── tmp/ --- temporary files
├── docs/ --- document files
├── lib/ --- server libraries
└── public/ --- client files
├── css/ --- css styles
├── js/ --- js scripts
├── vendor/ --- vendor includes
└── views/ --- view templates
```
## Operational Transformation
2016-10-04 04:41:26 -04:00
2017-10-29 06:16:40 -04:00
From 0.3.2, we started supporting operational transformation.
It makes concurrent editing safe and will not break up other users' operations.
Additionally, now can show other clients' selections.
2016-10-04 04:41:26 -04:00
See more at [http://operational-transformation.github.io/ ](http://operational-transformation.github.io/ )
2015-05-07 23:52:30 -04:00
2017-10-08 07:37:20 -04:00
# License
2015-09-24 22:39:09 -04:00
**License under MIT.**
2017-03-14 11:30:35 -04:00
2017-02-15 05:14:58 -05:00
[gitter-image]: https://badges.gitter.im/Join%20Chat.svg
[gitter-url]: https://gitter.im/hackmdio/hackmd?utm_source=badge& utm_medium=badge& utm_campaign=pr-badge& utm_content=badge
[travis-image]: https://travis-ci.org/hackmdio/hackmd.svg?branch=master
[travis-url]: https://travis-ci.org/hackmdio/hackmd
2017-10-08 07:15:29 -04:00
[github-version-badge]: https://img.shields.io/github/release/hackmdio/hackmd.svg
[github-release-page]: https://github.com/hackmdio/hackmd/releases
2017-03-14 11:30:35 -04:00
[standardjs-image]: https://cdn.rawgit.com/feross/standard/master/badge.svg
[standardjs-url]: https://github.com/feross/standard