mirror of
https://github.com/HackPlan/RootPanel.git
synced 2026-01-13 07:01:20 +08:00
refactor database
This commit is contained in:
15
app.coffee
15
app.coffee
@@ -3,7 +3,6 @@ path = require 'path'
|
||||
harp = require 'harp'
|
||||
fs = require 'fs'
|
||||
moment = require 'moment'
|
||||
mongomin = require 'mongo-min'
|
||||
redis = require 'redis'
|
||||
|
||||
global.app = express()
|
||||
@@ -30,20 +29,16 @@ bindRouters = ->
|
||||
app.get '/', (req, res) ->
|
||||
res.redirect '/panel/'
|
||||
|
||||
exports.connectDatabase = (callback) ->
|
||||
exports.run = ->
|
||||
{user, password, host, name} = config.mongodb
|
||||
mongomin "mongodb://#{user}:#{password}@#{host}/#{name}", (err, db) ->
|
||||
|
||||
MongoClient.connect "mongodb://#{user}:#{password}@#{host}/#{name}", (err, db) ->
|
||||
throw err if err
|
||||
app.db = db
|
||||
|
||||
app.redis = redis.createClient 6379, '127.0.0.1',
|
||||
auth_pass: config.redis_password
|
||||
|
||||
callback err
|
||||
|
||||
exports.run = ->
|
||||
exports.connectDatabase (err) ->
|
||||
throw err if err
|
||||
|
||||
app.package = require './package.json'
|
||||
|
||||
app.use connect.json()
|
||||
@@ -51,8 +46,6 @@ exports.run = ->
|
||||
app.use connect.cookieParser()
|
||||
app.use connect.logger('dev')
|
||||
|
||||
moment.locale 'zh_CN'
|
||||
|
||||
app.use (req, res, next) ->
|
||||
res.locals.app = app
|
||||
res.locals.t = i18n.getTranslator req.cookies.language
|
||||
|
||||
@@ -6,11 +6,7 @@ bitcoin = require '../bitcoin'
|
||||
|
||||
mBalance = require './balance'
|
||||
|
||||
module.exports = exports = app.db.buildModel 'accounts'
|
||||
|
||||
exports.byUsername = exports.buildByXXOO 'username'
|
||||
exports.byEmail = exports.buildByXXOO 'email'
|
||||
exports.byDepositAddress = exports.buildByXXOO 'attribute.bitcoin_deposit_address'
|
||||
module.exports = exports = app.db.collection 'accounts'
|
||||
|
||||
sample =
|
||||
username: 'jysperm'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module.exports = exports = app.db.buildModel 'balance_log'
|
||||
module.exports = exports = app.db.collection 'balance_log'
|
||||
|
||||
sample =
|
||||
account_id: new ObjectID()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
mAccount = require './account'
|
||||
|
||||
module.exports = exports = app.db.buildModel 'coupon_code'
|
||||
module.exports = exports = app.db.collection 'coupon_code'
|
||||
|
||||
sample =
|
||||
code: 'PmlFH2hpziDmyqPX'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module.exports = exports = app.db.buildModel 'security_log'
|
||||
module.exports = exports = app.db.collection 'security_log'
|
||||
|
||||
sample =
|
||||
account_id: new ObjectID()
|
||||
|
||||
@@ -2,7 +2,7 @@ markdown = require('markdown').markdown
|
||||
|
||||
mAccount = require './account'
|
||||
|
||||
module.exports = exports = app.db.buildModel 'tickets'
|
||||
module.exports = exports = app.db.collection 'tickets'
|
||||
|
||||
sample =
|
||||
account_id: ObjectID()
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
"mysql": "~2.4.2",
|
||||
"moment-timezone": "~0.2.2",
|
||||
"request": "~2.40.0",
|
||||
"mongo-min": "~0.2.2",
|
||||
"redis": "~0.12.1",
|
||||
"nodemailer": "~0.7.1"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user