Permalink
Browse files

Jump to 0.3.1

  • Loading branch information...
jackycute committed Jul 1, 2015
1 parent f7f8c90 commit 10c9811fc534a2738c19d8f74a447ed500b730a2
Showing with 2,332 additions and 444 deletions.
  1. +38 −20 README.md
  2. +39 −28 app.js
  3. 0 backups/.keep
  4. +1 −1 config.js
  5. +11 −0 hackmd
  6. +7 −6 lib/auth.js
  7. +18 −17 lib/db.js
  8. +2 −1 lib/logger.js
  9. +147 −6 lib/note.js
  10. +234 −94 lib/realtime.js
  11. +158 −19 lib/response.js
  12. +7 −6 lib/temp.js
  13. +6 −5 lib/user.js
  14. 0 logs/.keep
  15. +5 −2 package.json
  16. +19 −0 processes.json
  17. +16 −1 public/css/cover.css
  18. +171 −1 public/css/extra.css
  19. +22 −2 public/css/index.css
  20. +6 −0 public/css/site.css
  21. +25 −9 public/index.html
  22. +117 −13 public/js/cover.js
  23. +230 −63 public/js/extra.js
  24. +0 −8 public/js/fb.js
  25. +2 −1 public/js/history.js
  26. +444 −97 public/js/index.js
  27. +78 −6 public/js/pretty.js
  28. +7 −6 public/js/syncscroll.js
  29. +1 −1 public/vendor/codemirror/addon/comment/continuecomment.js
  30. +2 −2 public/vendor/codemirror/codemirror.min.js
  31. +4 −2 public/vendor/codemirror/lib/codemirror.js
  32. +1 −0 public/vendor/highlight-js/github-gist.min.css
  33. +1 −1 public/vendor/highlight-js/github.min.css
  34. +2 −2 public/vendor/highlight-js/highlight.min.js
  35. +2 −0 public/vendor/inlineAttachment/codemirror.inline-attachment.js
  36. +1 −1 public/vendor/inlineAttachment/inline-attachment.js
  37. +33 −6 public/vendor/jquery-textcomplete/jquery.textcomplete.js
  38. +8 −0 public/vendor/jquery.mousewheel.min.js
  39. +121 −0 public/vendor/md-toc.js
  40. +1 −0 public/vendor/md5.min.js
  41. +125 −0 public/vendor/showup/showup.css
  42. +87 −0 public/vendor/showup/showup.js
  43. +87 −1 public/views/body.ejs
  44. +5 −0 public/views/foot.ejs
  45. +4 −4 public/views/head.ejs
  46. +9 −3 public/views/header.ejs
  47. +27 −8 public/views/pretty.ejs
  48. +1 −1 run.sh
  49. 0 tmp/.keep
View
@@ -1,52 +1,70 @@
HackMD 0.2.9
HackMD 0.3.1
===
HackMD is a realtime collaborative markdown notes on all platforms.
Inspired by Hackpad, but more focusing on speed and flexibility.
Still in early stage, feel free to fork or contribute to this.
HackMD is a realtime collaborative markdown notes on all platforms.
Inspired by Hackpad, but more focusing on speed and flexibility.
Still in early stage, feel free to fork or contribute to this.
Thanks for your using! :smile:
Dependency
Database dependency
---
- PostgreSQL 9.3.6 or 9.4.1
- MongoDB 3.0.2
Import db schema
Import database schema
---
The notes are store in PostgreSQL, the schema is in the `hackmd_schema.sql`
The notes are store in PostgreSQL, the schema is in the `hackmd_schema.sql`
To import the sql file in PostgreSQL, type `psql -i hackmd_schema.sql`
The users, temps and sessions are store in MongoDB, which don't need schema, so just make sure you have the correct connection string.
The users, temps and sessions are store in MongoDB, which don't need schema, so just make sure you have the correct connection string.
Config
Structure
---
```
hackmd/
├── logs/ --- server logs
├── backups/ --- db backups
├── tmp/ --- temporary files
├── lib/ --- server libraries
└── public/ --- client files
├── css/ --- css styles
├── js/ --- js scripts
├── vendor/ --- vendor includes
└── views/ --- view templates
```
Configure
---
There are some config you need to change in below files
```
./run.sh
./config.js
./public/js/common.js
./Procfile --- for heroku start
./run.sh --- for forever start
./processes.json --- for pm2 start
./config.js --- for server settings
./public/js/common.js --- for client settings
./hackmd --- for logrotate
```
The script `run.sh`, it's for someone like me to run the server via npm package `forever`, and can passing environment variable to the server, like heroku does.
**From 0.3.1, we no longer recommend using `forever` to run your server.**
To install `forever`, just type `npm install forever -g`
We using `pm2` to run server.
See [here](https://github.com/Unitech/pm2) for details.
You can use SSL to encrypt your site by passing certificate path in the `config.js` and set `usessl=true`
Run a server
---
To run the server, type `bash run.sh`
Log will be at `~/.forever/hackmd.log`
- forever: `bash run.sh`
- pm2: `pm2 start processes.json`
Stop a server
---
To stop the server, simply type `forever stop hackmd`
- forever: `forever stop hackmd`
- pm2: `pm2 stop hackmd`
Backup db
---
To backup the db, type `bash backup.sh`
Backup files will be at `./backups/`
To backup the db, type `bash backup.sh`
**License under MIT.**
View
67 app.js
@@ -49,13 +49,15 @@ if (config.usessl) {
var app = express();
var server = require('http').createServer(app);
}
//socket io listen
var io = require('socket.io').listen(server);
//logger
app.use(morgan('combined', {
"stream": logger.stream
}));
//socket io
var io = require('socket.io')(server);
// connect to the mongodb
mongoose.connect(process.env.MONGOLAB_URI || config.mongodbstring);
@@ -80,7 +82,7 @@ var sessionStore = new MongoStore({
touchAfter: config.sessiontouch
},
function (err) {
console.log(err);
logger.info(err);
});
//compression
@@ -115,12 +117,12 @@ app.use(passport.session());
//serialize and deserialize
passport.serializeUser(function (user, done) {
//console.log('serializeUser: ' + user._id);
//logger.info('serializeUser: ' + user._id);
done(null, user._id);
});
passport.deserializeUser(function (id, done) {
User.model.findById(id, function (err, user) {
//console.log(user)
//logger.info(user)
if (!err) done(null, user);
else done(err, null);
})
@@ -163,7 +165,7 @@ app.get("/temp", function (req, res) {
});
temp.remove(function (err) {
if (err)
console.log('remove temp failed: ' + err);
logger.error('remove temp failed: ' + err);
});
}
});
@@ -182,7 +184,7 @@ app.post("/temp", urlencodedParser, function (req, res) {
response.errorForbidden(res);
else {
if (config.debug)
console.log('SERVER received temp from [' + host + ']: ' + req.body.data);
logger.info('SERVER received temp from [' + host + ']: ' + req.body.data);
Temp.newTemp(id, data, function (err, temp) {
if (!err && temp) {
res.header("Access-Control-Allow-Origin", "*");
@@ -247,7 +249,7 @@ app.get('/auth/dropbox/callback',
//logout
app.get('/logout', function (req, res) {
if (config.debug && req.session.passport.user)
console.log('user logout: ' + req.session.passport.user);
logger.info('user logout: ' + req.session.passport.user);
req.logout();
res.redirect('/');
});
@@ -256,7 +258,7 @@ app.get('/history', function (req, res) {
if (req.isAuthenticated()) {
User.model.findById(req.session.passport.user, function (err, user) {
if (err) {
console.log('read history failed: ' + err);
logger.error('read history failed: ' + err);
} else {
var history = [];
if (user.history)
@@ -274,18 +276,18 @@ app.get('/history', function (req, res) {
app.post('/history', urlencodedParser, function (req, res) {
if (req.isAuthenticated()) {
if (config.debug)
console.log('SERVER received history from [' + req.session.passport.user + ']: ' + req.body.history);
logger.info('SERVER received history from [' + req.session.passport.user + ']: ' + req.body.history);
User.model.findById(req.session.passport.user, function (err, user) {
if (err) {
console.log('write history failed: ' + err);
logger.error('write history failed: ' + err);
} else {
user.history = req.body.history;
user.save(function (err) {
if (err) {
console.log('write user history failed: ' + err);
logger.error('write user history failed: ' + err);
} else {
if (config.debug)
console.log("write user history success: " + user._id);
logger.info("write user history success: " + user._id);
};
});
}
@@ -300,7 +302,7 @@ app.get('/me', function (req, res) {
if (req.isAuthenticated()) {
User.model.findById(req.session.passport.user, function (err, user) {
if (err) {
console.log('read me failed: ' + err);
logger.error('read me failed: ' + err);
} else {
var profile = JSON.parse(user.profile);
res.send({
@@ -324,27 +326,36 @@ app.post('/uploadimage', function (req, res) {
response.errorForbidden(res);
} else {
if (config.debug)
console.log('SERVER received uploadimage: ' + JSON.stringify(files.image));
logger.info('SERVER received uploadimage: ' + JSON.stringify(files.image));
imgur.setClientId(config.imgur.clientID);
imgur.uploadFile(files.image.path)
.then(function (json) {
if (config.debug)
console.log('SERVER uploadimage success: ' + JSON.stringify(json));
res.send({
link: json.data.link
try {
imgur.uploadFile(files.image.path)
.then(function (json) {
if (config.debug)
logger.info('SERVER uploadimage success: ' + JSON.stringify(json));
res.send({
link: json.data.link
});
})
.catch(function (err) {
logger.error(err);
res.send('upload image error');
});
})
.catch(function (err) {
console.error(err);
res.send(err.message);
});
} catch (err) {
logger.error(err);
res.send('upload image error');
}
}
});
});
//get new note
app.get("/new", response.newNote);
//get features
app.get("/features", response.showFeatures);
//get share note
app.get("/s/:shortid", response.showShareNote);
//share note actions
app.get("/s/:shortid/:action", response.shareNoteActions);
//get note by id
app.get("/:noteId", response.showNote);
//note actions
@@ -370,10 +381,10 @@ io.sockets.on('connection', realtime.connection);
//listen
if (config.usessl) {
server.listen(config.sslport, function () {
console.log('HTTPS Server listening at sslport %d', config.sslport);
logger.info('HTTPS Server listening at sslport %d', config.sslport);
});
} else {
server.listen(config.port, function () {
console.log('HTTP Server listening at port %d', config.port);
logger.info('HTTP Server listening at port %d', config.port);
});
}
View
No changes.
View
@@ -11,7 +11,7 @@ var urladdport = true; //add port on getserverurl
var config = {
debug: true,
version: '0.2.8',
version: '0.3.1',
domain: domain,
alloworigin: ['add here to allow origin to cross'],
testport: testport,
View
11 hackmd
@@ -0,0 +1,11 @@
/home/hackmd/logs/*.log {
daily
rotate 365
missingok
notifempty
compress
sharedscripts
copytruncate
dateext
dateformat %Y-%m-%d
}
View
@@ -7,17 +7,18 @@ var GithubStrategy = require('passport-github').Strategy;
var DropboxStrategy = require('passport-dropbox-oauth2').Strategy;
//core
var User = require('./user.js')
var config = require('../config.js')
var User = require('./user.js');
var config = require('../config.js');
var logger = require("./logger.js");
function callback(accessToken, refreshToken, profile, done) {
//console.log(profile.displayName || profile.username);
//logger.info(profile.displayName || profile.username);
User.findOrNewUser(profile.id, profile, function (err, user) {
if (err || user == null) {
console.log('auth callback failed: ' + err);
logger.error('auth callback failed: ' + err);
} else {
if(config.debug && user)
console.log('user login: ' + user._id);
if (config.debug && user)
logger.info('user login: ' + user._id);
done(null, user);
}
});
Oops, something went wrong.

0 comments on commit 10c9811

Please sign in to comment.