Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
jcpwfloi committed Jan 2, 2016
0 parents commit fc12064
Show file tree
Hide file tree
Showing 61 changed files with 3,775 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
*.log
.DS_Store

20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2014 jcpwfloi

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 华师大二附中表白墙

## 萌萌哒表白墙Installation

对于linux/unix/mac用户:

```bash
# 对于Ubuntu用户需要:
apt-get install git git-core gyp
# 对于CentOS用户需要:
yum install git git-core gyp
git clone https://github.com/joyent/node
./configure
make
sudo make install
```

对于mac用户的简便安装:

1. 先安装homebrew

```bash
brew install node
```

对于windows用户:访问[NodeJS](http://nodejs.org/),自行解决。

## 萌萌哒数据库安装

### 安装MongoDB

对于Mac用户:brew install mongodb

对于Ubuntu用户:apt-get install mongodb

对于CentOS用户:yum install mongodb

对于Windows用户:自己看着办

### 挂载MongoDB

对于Mac/Ubuntu/CentOS用户:

```bash
cd /
mkdir data
mkdir data/db
cd data/db
mongod --dbpath . &> mongodb.log &
```

## 开启服务器

进入源代码根目录后:

对于Mac/Ubuntu/CentOS用户:

```bash
npm install
npm start
```

对于Windows用户:自己看着办。


71 changes: 71 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var routes = require('./routes/index');
var post = require('./routes/post');
var view = require('./routes/view');
var search = require('./routes/search');
var apii = require('./routes/api');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));

//self
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(require('less-middleware')(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));

//app.use('*', function(req, res) {res.send('服务器维护中')});

app.use('/', routes);
app.use('/post', post);
app.use('/view', view);
app.use('/search', search);
app.use('/api', apii);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});


module.exports = app;
9 changes: 9 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node
var debug = require('debug')('hsefz');
var app = require('../app');

app.set('port', process.env.PORT || 3000);

var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
});
58 changes: 58 additions & 0 deletions model/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var mongo = require('mongodb');
var server = new mongo.Server('127.0.0.1', 27017);
var db = new mongo.Db('bbq', server, {safe: true});

db.open(function(err, db) {});

function getTotal(callback) {
db.collection('core', function(err, collection) {
collection.findOne({name: 'total'}, function(err, doc) {
callback(err, doc);
});
});
}

function addTotal(callback) {
db.collection('core', function(err, collection) {
collection.update({name: 'total'}, {$inc: {value: 1}}, function(err, doc) {
callback(err, doc);
});
});
}

function getBBQByAmount(skip, amount, callback) {
db.collection('posts', function(err, collection) {
collection.find({del: {$ne: true}}, {sort: {id: -1}, skip: skip, limit: amount}, function(err, doc) {
doc.toArray(function(err, arr) {
callback(err, arr);
});
});
});
}

function postBBQ(bbq, callback) {
db.collection('posts', function(err, collection) {
collection.insert(bbq, function(err, doc) {
callback(err, doc);
});
});
}

function searchBBQ(keyword, callback, skip, limit) {
if (!skip) skip = 0;
if (!limit) limit = 30;
db.collection('posts', function(err, collection) {
collection.find({del: {$exists: false}, $or: [{title: RegExp(keyword)}, {content: new RegExp(keyword)}]}, {sort: {id: -1}, limit: limit, skip: skip}, function(err, doc) {
doc.toArray(function(err, arr) {
callback(err, arr);
});
});
});
}

exports.getTotal = getTotal;
exports.addTotal = addTotal;
exports.getBBQByAmount = getBBQByAmount;
exports.postBBQ = postBBQ;
exports.searchBBQ = searchBBQ;

20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "hsefz",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.8.1",
"compression": "^1.2.2",
"cookie-parser": "~1.3.3",
"debug": "~2.0.0",
"express": "~4.9.0",
"jade": "~1.6.0",
"less-middleware": "1.0.x",
"mongodb": "^1.4.20",
"morgan": "~1.3.0",
"serve-favicon": "~2.1.3"
}
}
4 changes: 4 additions & 0 deletions public/css/font-awesome.min.css

Large diffs are not rendered by default.

Loading

0 comments on commit fc12064

Please sign in to comment.