mirror of
https://github.com/wassname/talk.git
synced 2026-07-18 12:40:13 +08:00
update routes and paths. add init script
This commit is contained in:
@@ -3,3 +3,4 @@ npm-debug.log
|
||||
dist
|
||||
.DS_Store
|
||||
*.iml
|
||||
.env
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
const MongoClient = require('mongodb').MongoClient;
|
||||
const url = process.env.TALK_MONGO_URL;
|
||||
|
||||
if (!url) {
|
||||
throw new Error('environment variable TALK_MONGO_URL must be defined');
|
||||
}
|
||||
|
||||
MongoClient.connect(url).then(db => {
|
||||
const Setting = db.collection('settings');
|
||||
const defaults = {id: 1, moderation: 'pre'};
|
||||
|
||||
Setting.update({id: 1}, {$setOnInsert: defaults}, {upsert: true}).then(() => {
|
||||
console.log('created settings object.');
|
||||
process.exit();
|
||||
});
|
||||
}).catch(console.error);
|
||||
+3
-3
@@ -3,8 +3,7 @@ const Schema = mongoose.Schema;
|
||||
|
||||
const SettingSchema = new Schema({
|
||||
id: {type: String, default: '1'},
|
||||
moderation: {type: String, enum: ['pre', 'post'], default: 'pre'},
|
||||
|
||||
moderation: {type: String, enum: ['pre', 'post'], default: 'pre'}
|
||||
}, {
|
||||
_id: false,
|
||||
timestamps: {
|
||||
@@ -18,7 +17,8 @@ SettingSchema.statics.getSettings = function () {
|
||||
};
|
||||
|
||||
SettingSchema.statics.updateSettings = function (setting) {
|
||||
return this.findOneAndUpdate({}, {$set: setting}, {new: true});
|
||||
// there should only ever be one record unless something has gone wrong.
|
||||
return this.findOneAndUpdate({id: '1'}, {$set: setting}, {new: true});
|
||||
};
|
||||
|
||||
const Setting = mongoose.model('Setting', SettingSchema);
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
"imports-loader": "^0.6.5",
|
||||
"json-loader": "^0.5.4",
|
||||
"mocha": "^3.1.2",
|
||||
"mongodb": "^2.2.11",
|
||||
"pre-git": "^3.10.0",
|
||||
"pym.js": "^1.1.1",
|
||||
"react": "15.3.2",
|
||||
|
||||
@@ -3,5 +3,6 @@ const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
router.use('/comments', require('./comments'));
|
||||
router.use('/settings', require('./settings'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const path = require('path');
|
||||
const Setting = require(path.resolve(__dirname, 'models/setting'));
|
||||
const Setting = require('../../../models/setting');
|
||||
|
||||
router.get('/settings', (req, res, next) => {
|
||||
router.get('/', (req, res, next) => {
|
||||
Setting.getSettings().then(res.json).catch(next);
|
||||
});
|
||||
|
||||
router.put('/settings', (req, res, next) => {
|
||||
router.put('/', (req, res, next) => {
|
||||
Setting.updateSettings(req.body).then(res.json).catch(next);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user