diff --git a/server/.babelrc b/server/.babelrc new file mode 100644 index 0000000..514885c --- /dev/null +++ b/server/.babelrc @@ -0,0 +1,7 @@ +{ + "presets": ["es2015", "stage-2", "react"], + "plugins": ["syntax-async-functions","transform-regenerator", "transform-object-assign", + "transform-object-rest-spread","transform-react-jsx-source"], + "sourceMaps": true, + "retainLines": true +} diff --git a/server/app.js b/server/app.js index a3da336..8802295 100644 --- a/server/app.js +++ b/server/app.js @@ -3,16 +3,16 @@ */ import 'babel-polyfill' -import express from 'express'; -import mongoose from 'mongoose'; -import hbs from 'express-hbs'; +import express from 'express'; +import mongoose from 'mongoose'; +import hbs from 'express-hbs'; -import SiteServer from './SiteServer'; -import models from './models'; -import api from './controllers/api'; +import SiteServer from './SiteServer'; +import models from './models'; +import api from './controllers/api'; import middleware from './middleware'; -import helpers from './helpers'; -import errors from './errors'; +import helpers from './helpers'; +import errors from './errors'; function init() { var apiApp = express(), // API @@ -23,7 +23,9 @@ function init() { // TODO: configure this connection string. mongoose.connect('mongodb://localhost:27017/petshop'); }).then(() => { - models.init(); + // no longer needed, no dynamic load for import key word + // models.init(); + console.log('===>models init'); }).then(() => { api.init(); }).then(() => { diff --git a/server/controllers/auth.js b/server/controllers/auth.js index 08a64ee..2cffe9a 100644 --- a/server/controllers/auth.js +++ b/server/controllers/auth.js @@ -58,6 +58,8 @@ passport.use(new BasicStrategy( // return done(err); // }); + console.log('===>controller/auth, 61', dataProvider); + dataProvider.User.findOne({ username: username }).exec().then((u) => { if (!u) { done(null, false); diff --git a/server/controllers/pet.js b/server/controllers/pet.js index ec6483f..a1767e5 100644 --- a/server/controllers/pet.js +++ b/server/controllers/pet.js @@ -4,7 +4,7 @@ import * as _ from 'lodash' import utils from '../utils' -import dataProvider from '../models/pet' +import dataProvider from '../models' // import Accessory from '../models/accessory').model; var postPets = function (req, res) { diff --git a/server/models/accessory.js b/server/models/accessory.js index 2b57f79..97af6ab 100644 --- a/server/models/accessory.js +++ b/server/models/accessory.js @@ -6,12 +6,9 @@ import mongoose from './base'; var Schema = mongoose.BaseSchema; -var AccessorySchema = new Schema({ - name: {type: String, required: true}, - price: {type: Number, required: true} +export var AccessorySchema = new Schema({ + name: { type: String, required: true }, + price: { type: Number, required: true } }); -export default { - schema: AccessorySchema, - model: mongoose.model('accessories', AccessorySchema) -}; +export default mongoose.model('accessories', AccessorySchema); diff --git a/server/models/client.js b/server/models/client.js index 8441d71..adb78f4 100644 --- a/server/models/client.js +++ b/server/models/client.js @@ -11,6 +11,4 @@ var clientSchema = new mongoose.BaseSchema({ userId: {type: String, required: true} }); -export default { - Client: mongoose.model('client', clientSchema) -}; \ No newline at end of file +export default mongoose.model('client', clientSchema); \ No newline at end of file diff --git a/server/models/code.js b/server/models/code.js index c28d6bd..8d87114 100644 --- a/server/models/code.js +++ b/server/models/code.js @@ -2,16 +2,14 @@ * Created by Uncle Charlie, 2017/03/01 */ -import mongoose from './base'; +import mongoose from './base'; var Schema = mongoose.BaseSchema; var codeSchema = new Schema({ - value: {type: String, required: true}, - redirectUri: {type: String, required: true}, - userId: {type: String, required: true}, - clientId: {type: String, required: true} + value: { type: String, required: true }, + redirectUri: { type: String, required: true }, + userId: { type: String, required: true }, + clientId: { type: String, required: true } }); -module.exports = { - Code: mongoose.model('code', codeSchema) -}; \ No newline at end of file +export default mongoose.model('code', codeSchema); \ No newline at end of file diff --git a/server/models/index.js b/server/models/index.js index 0273b22..0565acf 100644 --- a/server/models/index.js +++ b/server/models/index.js @@ -4,24 +4,43 @@ import * as _ from 'lodash'; -let exports = module.exports; +// let exports = module.exports; -let models = [ - 'accessory', - 'client', - 'code', - 'pet', - 'token', - 'user' -]; +// let models = [ +// 'accessory', +// 'client', +// 'code', +// 'pet', +// 'token', +// 'user' +// ]; -function init() { - exports.Base = require('./base'); +// function init() { +// exports.Base = require('./base'); - models.forEach(function (name) { - _.extend(exports, require('./' + name)); - }); -} +// models.forEach(function (name) { +// _.extend(exports, require('./' + name)); +// }); +// } +// // exports.init = init; // exports.init = init; -exports.init = init; \ No newline at end of file + + +import _user from './user'; +import _accessory, { AccessorySchema } from './accessory'; +import _client from './client'; +import _code from './code'; +import _pet from './pet'; +import _token from './token'; + +export default { + User: _user, + Accessory: _accessory, + Client: _client, + Code: _code, + Pet: _pet, + Token: _token, + AccessorySchema, + init: () => { console.log('===> models init()') } +}; \ No newline at end of file diff --git a/server/models/pet.js b/server/models/pet.js index 7e51fb7..26656d1 100644 --- a/server/models/pet.js +++ b/server/models/pet.js @@ -70,6 +70,4 @@ petSchema.static('findFull', function (options, callback) { // return this.find({}).populate('users').exec(callback); }); -export default { - Pet: mongoose.model('pet', petSchema) -}; \ No newline at end of file +export default mongoose.model('pet', petSchema); \ No newline at end of file diff --git a/server/models/token.js b/server/models/token.js index 0e1b304..c66080c 100644 --- a/server/models/token.js +++ b/server/models/token.js @@ -11,6 +11,4 @@ var tokenSchema = new Schema({ clientId: { type: String, required: true } }); -export default { - Token: mongoose.model('token', tokenSchema) -}; \ No newline at end of file +export default mongoose.model('token', tokenSchema); \ No newline at end of file diff --git a/server/models/user.js b/server/models/user.js index 92d35b9..ef37376 100644 --- a/server/models/user.js +++ b/server/models/user.js @@ -116,6 +116,4 @@ userSchema.methods.verifyPassword = function (password, callback) { }); }; -export default { - User: mongoose.model('User', userSchema) -}; \ No newline at end of file +export default mongoose.model('User', userSchema);