Skip to content

Commit 1a190a7

Browse files
author
郑望
committed
增加项目
1 parent c7494ad commit 1a190a7

19 files changed

+461
-0
lines changed

Gruntfile.coffee

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
'use strict';
2+
3+
module.exports = (grunt) ->
4+
grunt.initConfig
5+
pkg: grunt.file.readJSON('package.json')
6+
7+
requirejs:
8+
compile:
9+
options:
10+
baseUrl: 'src/js'
11+
mainConfigFile: 'src/js/main.js'
12+
paths:
13+
jquery: '../../lib/jquery.min',
14+
'smart.ui': '../../lib/smart.ui.min',
15+
underscore: '../../lib/underscore.min',
16+
backbone: '../../lib/backbone.min',
17+
bootstrap: '../../lib/bootstrap.min'
18+
include: ['require','jquery', 'smart.ui', 'underscore', 'backbone', 'bootstrap','main']
19+
out: 'dist/js/<%= pkg.name %>.js'
20+
21+
concat:
22+
options:
23+
banner: '/*! APP.common.css@<%= pkg.name %> - v<%= pkg.version %> - ' +
24+
'<%= grunt.template.today("yyyy-mm-dd") %> */'
25+
js:
26+
src: ['src/js/*.js']
27+
dest: 'dist/js/<%= pkg.name %>.js'
28+
29+
jshint:
30+
grunt:
31+
src: [ 'Gruntfile.js' ]
32+
options:
33+
jshintrc: '.jshintrc'
34+
35+
dist:
36+
src: 'dist/js/<%= pkg.name %>.js'
37+
options:
38+
jshintrc: 'src/.jshintrc'
39+
40+
sass:
41+
dist:
42+
files:
43+
'public/css/<%= pkg.name %>.css': 'public/sass/main.scss'
44+
45+
options:
46+
sourcemap: 'true'
47+
48+
uglify:
49+
options:
50+
banner: "/*! <%= pkg.name %> <%= pkg.version %> */\n"
51+
release:
52+
files:
53+
'dist/js/<%= pkg.name %>.min.js': 'dist/js/<%= pkg.name %>.js'
54+
55+
cssmin:
56+
combine:
57+
files:
58+
'public/css/<%= pkg.name %>.min.css': 'public/css/<%= pkg.name %>.css'
59+
60+
qunit:
61+
all: ['test/index.html']
62+
63+
watch:
64+
script:
65+
files: ['public/sass/**/*.scss', 'Gruntfile.coffee']
66+
tasks: ['sass', 'cssmin']
67+
68+
69+
grunt.loadNpmTasks 'grunt-contrib-sass'
70+
grunt.loadNpmTasks 'grunt-contrib-cssmin'
71+
grunt.loadNpmTasks 'grunt-contrib-watch'
72+
73+
grunt.registerTask 'default', ['sass','cssmin','watch']

app.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
var path = require('path');
2+
3+
var express = require('express');
4+
var app = express();
5+
var favicon = require('static-favicon');
6+
var logger = require('morgan');
7+
var cookieParser = require('cookie-parser');
8+
var bodyParser = require('body-parser');
9+
10+
var routes = require('./routes/index');
11+
12+
//express基本配置
13+
app.set('port', process.env.PORT || 3000);
14+
app.set('views', __dirname + '/views');
15+
app.set('view engine', 'ejs');
16+
17+
app.use(favicon());
18+
app.use(logger('dev'));
19+
app.use(bodyParser.json());
20+
app.use(bodyParser.urlencoded());
21+
app.use(cookieParser());
22+
app.use(express.static(path.join(__dirname, 'public'), {
23+
maxAge: 86400000
24+
}));
25+
26+
app.use('/', routes);
27+
28+
var server = app.listen(app.get('port'), function() {
29+
console.log('Listening on port %d', server.address().port);
30+
});

config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"use strict";
2+
3+
exports.debug = true;
4+
exports.port = 3000;
5+
exports.email = '[email protected]';
6+
exports.site_name = 'chat_web';
7+
exports.site_desc = 'Very simple todo, demo for connect web dev.';
8+
exports.session_secret = 'todo session secret';
9+
10+
exports.db = 'mongodb://127.0.0.1:27017/data';

models/db.js

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
var mongoose = require('mongoose');
2+
var bson = require('bson');
3+
var Schema = mongoose.Schema;
4+
var dbURL = require("../config").db; //数据库地址
5+
6+
exports.connect = function(callback) {
7+
mongoose.connect(dbURL, callback);
8+
};
9+
10+
exports.disconnect = function(callback) {
11+
mongoose.disconnect(callback);
12+
}
13+
14+
//定义chat对象模型
15+
var UserSchema = new Schema({
16+
username: String,
17+
password: String
18+
});
19+
20+
//访问User对象模型
21+
mongoose.model('User', UserSchema);
22+
var User = mongoose.model('User');
23+
24+
exports.add = function(userInfo, callback) {
25+
var user = new User(userInfo);
26+
27+
user.save(function(error) {
28+
console.log(error)
29+
if (error) {
30+
util.log("FATAL" + error);
31+
callback(error);
32+
} else {
33+
callback(null);
34+
}
35+
});
36+
37+
};
38+
39+
exports.delete = function(name, callback) {
40+
exports.findTodoByName(name, function(error, doc) {
41+
if (error)
42+
callback(error);
43+
else {
44+
util.log(util.inspect(doc));
45+
doc.remove();
46+
callback(null);
47+
}
48+
});
49+
};
50+
51+
exports.allUsers = function(callback) {
52+
User.find({}, callback);
53+
};
54+
55+
exports.forAll = function(doEach, done) {
56+
User.find({}, function(error, docs) {
57+
if (error) {
58+
util.log('FATAL ' + error);
59+
done(error, null);
60+
}
61+
docs.forEach(function(doc) {
62+
doEach(null, doc);
63+
});
64+
done(null);
65+
});
66+
};
67+
68+
var findUserByName = exports.findUserByName = function(name, callback) {
69+
User.findOne({
70+
_name: name
71+
}, function(error, doc) {
72+
if (error) {
73+
util.log('FATAL ' + error);
74+
callback(error, null);
75+
}
76+
callback(null, doc);
77+
});
78+
};

package.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "chat_web",
3+
"version": "0.0.1",
4+
"private": true,
5+
"dependencies": {
6+
"log4js": "*",
7+
"body-parser": "~1.0.0",
8+
"cookie-parser": "~1.0.1",
9+
"debug": "~0.7.4",
10+
"ejs": "~0.8.5",
11+
"express": "~4.2.0",
12+
"mongoose": "*",
13+
"bson": "*",
14+
"morgan": "~1.0.0",
15+
"socket.io": "^1.0.6",
16+
"static-favicon": "~1.0.0",
17+
"xss-escape": "0.0.5",
18+
"grunt": "*",
19+
"grunt-contrib-sass": "",
20+
"grunt-contrib-cssmin": "*",
21+
"grunt-contrib-watch": "*"
22+
}
23+
}

public/css/chat_web.css

+48
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/css/chat_web.css.map

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/css/chat_web.min.css

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/lib/jquery.min.js

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)