diff --git a/server/achievements/Achievement.coffee b/server/achievements/Achievement.coffee index 3190a3c23..f6f26bbed 100644 --- a/server/achievements/Achievement.coffee +++ b/server/achievements/Achievement.coffee @@ -5,6 +5,7 @@ utils = require '../../app/core/utils' plugins = require('../plugins/plugins') AchievablePlugin = require '../plugins/achievements' TreemaUtils = require '../../bower_components/treema/treema-utils.js' +config = require '../../server_config' # `pre` and `post` are not called for update operations executed directly on the database, # including `Model.update`,`.findByIdAndUpdate`,`.findOneAndUpdate`, `.findOneAndRemove`,and `.findByIdAndRemove`.order @@ -13,7 +14,7 @@ TreemaUtils = require '../../bower_components/treema/treema-utils.js' AchievementSchema = new mongoose.Schema({ userField: String -}, {strict: false,read:'nearest'}) +}, {strict: false,read: config.mongo.readpref}) AchievementSchema.index( { diff --git a/server/articles/Article.coffee b/server/articles/Article.coffee index 0b69ceec0..cff703cd2 100644 --- a/server/articles/Article.coffee +++ b/server/articles/Article.coffee @@ -1,7 +1,8 @@ mongoose = require 'mongoose' plugins = require '../plugins/plugins' +config = require '../../server_config' -ArticleSchema = new mongoose.Schema(body: String, {strict: false,read:'nearest'}) +ArticleSchema = new mongoose.Schema(body: String, {strict: false,read:config.mongo.readpref}) ArticleSchema.index( { diff --git a/server/campaigns/Campaign.coffee b/server/campaigns/Campaign.coffee index b48ec0b1a..65a7ef614 100644 --- a/server/campaigns/Campaign.coffee +++ b/server/campaigns/Campaign.coffee @@ -1,8 +1,9 @@ mongoose = require 'mongoose' plugins = require '../plugins/plugins' log = require 'winston' +config = require '../../server_config' -CampaignSchema = new mongoose.Schema(body: String, {strict: false,read:'nearest'}) +CampaignSchema = new mongoose.Schema(body: String, {strict: false,read:config.mongo.readpref}) CampaignSchema.index({i18nCoverage: 1}, {name: 'translation coverage index', sparse: true}) CampaignSchema.index({slug: 1}, {name: 'slug index', sparse: true, unique: true}) diff --git a/server/levels/Level.coffee b/server/levels/Level.coffee index 29924522a..5eef1b747 100644 --- a/server/levels/Level.coffee +++ b/server/levels/Level.coffee @@ -1,10 +1,11 @@ mongoose = require 'mongoose' plugins = require '../plugins/plugins' jsonschema = require '../../app/schemas/models/level' +config = require '../../server_config' LevelSchema = new mongoose.Schema({ description: String -}, {strict: false, read:'nearest'}) +}, {strict: false, read:config.mongo.readpref}) LevelSchema.index( { diff --git a/server/levels/components/LevelComponent.coffee b/server/levels/components/LevelComponent.coffee index 3404ca6f6..68280f661 100644 --- a/server/levels/components/LevelComponent.coffee +++ b/server/levels/components/LevelComponent.coffee @@ -1,11 +1,12 @@ mongoose = require 'mongoose' plugins = require '../../plugins/plugins' jsonschema = require '../../../app/schemas/models/level_component' +config = require '../../../server_config' LevelComponentSchema = new mongoose.Schema { description: String system: String -}, {strict: false, read:'nearest'} +}, {strict: false, read:config.mongo.readpref} LevelComponentSchema.index( { diff --git a/server/levels/feedbacks/LevelFeedback.coffee b/server/levels/feedbacks/LevelFeedback.coffee index e13735f6f..1e3a47950 100644 --- a/server/levels/feedbacks/LevelFeedback.coffee +++ b/server/levels/feedbacks/LevelFeedback.coffee @@ -3,12 +3,13 @@ mongoose = require 'mongoose' plugins = require '../../plugins/plugins' jsonschema = require '../../../app/schemas/models/level_feedback' +config = require '../../../server_config' LevelFeedbackSchema = new mongoose.Schema({ created: type: Date 'default': Date.now -}, {strict: false,read:'nearest'}) +}, {strict: false,read:config.mongo.readpref}) LevelFeedbackSchema.index({created: 1}) LevelFeedbackSchema.index({creator: 1}) diff --git a/server/levels/sessions/LevelSession.coffee b/server/levels/sessions/LevelSession.coffee index 74769ee89..abd1940a3 100644 --- a/server/levels/sessions/LevelSession.coffee +++ b/server/levels/sessions/LevelSession.coffee @@ -3,12 +3,13 @@ plugins = require '../../plugins/plugins' AchievablePlugin = require '../../plugins/achievements' jsonschema = require '../../../app/schemas/models/level_session' log = require 'winston' +config = require '../../../server_config' LevelSessionSchema = new mongoose.Schema({ created: type: Date 'default': Date.now -}, {strict: false,read:'nearest'}) +}, {strict: false,read:config.mongo.readpref}) LevelSessionSchema.index({creator: 1}) LevelSessionSchema.index({level: 1}) diff --git a/server/levels/systems/LevelSystem.coffee b/server/levels/systems/LevelSystem.coffee index 5d3830f5e..75398fb4b 100644 --- a/server/levels/systems/LevelSystem.coffee +++ b/server/levels/systems/LevelSystem.coffee @@ -1,10 +1,11 @@ mongoose = require 'mongoose' plugins = require '../../plugins/plugins' jsonschema = require '../../../app/schemas/models/level_system' +config = require '../../../server_config' LevelSystemSchema = new mongoose.Schema { description: String -}, {strict: false,read:'nearest'} +}, {strict: false,read:config.mongo.readpref} LevelSystemSchema.index( { diff --git a/server/levels/thangs/ThangType.coffee b/server/levels/thangs/ThangType.coffee index 973ecfcdd..732dc5f09 100644 --- a/server/levels/thangs/ThangType.coffee +++ b/server/levels/thangs/ThangType.coffee @@ -1,9 +1,10 @@ mongoose = require 'mongoose' plugins = require '../../plugins/plugins' +config = require '../../../server_config' ThangTypeSchema = new mongoose.Schema({ body: String, -}, {strict: false,read:'nearest'}) +}, {strict: false,read:config.mongo.readpref}) ThangTypeSchema.index( { diff --git a/server/patches/Patch.coffee b/server/patches/Patch.coffee index a5dd2a1a8..712d7cdb3 100644 --- a/server/patches/Patch.coffee +++ b/server/patches/Patch.coffee @@ -2,8 +2,9 @@ mongoose = require('mongoose') deltas = require '../../app/core/deltas' log = require 'winston' {handlers} = require '../commons/mapping' +config = require '../../server_config' -PatchSchema = new mongoose.Schema({status: String}, {strict: false,read:'nearest'}) +PatchSchema = new mongoose.Schema({status: String}, {strict: false,read:config.mongo.readpref}) PatchSchema.pre 'save', (next) -> return next() unless @isNew # patch can't be altered after creation, so only need to check data once diff --git a/server/payments/Payment.coffee b/server/payments/Payment.coffee index e74919858..c29814ed2 100644 --- a/server/payments/Payment.coffee +++ b/server/payments/Payment.coffee @@ -1,6 +1,7 @@ mongoose = require('mongoose') +config = require '../../server_config' -PaymentSchema = new mongoose.Schema({}, {strict: false, read:'nearest'}) +PaymentSchema = new mongoose.Schema({}, {strict: false, read:config.mongo.readpref}) PaymentSchema.index({recipient: 1, 'stripe.timestamp': 1, 'ios.transactionID'}, {unique: true, name: 'unique payment'}) module.exports = mongoose.model('payment', PaymentSchema) diff --git a/server/polls/Poll.coffee b/server/polls/Poll.coffee index f11881656..e6ad7a609 100644 --- a/server/polls/Poll.coffee +++ b/server/polls/Poll.coffee @@ -2,12 +2,12 @@ mongoose = require 'mongoose' plugins = require '../plugins/plugins' jsonSchema = require '../../app/schemas/models/poll.schema' log = require 'winston' - +config = require '../../server_config' PollSchema = new mongoose.Schema { created: type: Date 'default': Date.now -}, {strict: false, minimize: false,read:'nearest'} +}, {strict: false, minimize: false,read:config.mongo.readpref} PollSchema.index {priority: 1} diff --git a/server/prepaids/Prepaid.coffee b/server/prepaids/Prepaid.coffee index 4c55fb0ea..71a870bdc 100644 --- a/server/prepaids/Prepaid.coffee +++ b/server/prepaids/Prepaid.coffee @@ -1,5 +1,5 @@ mongoose = require 'mongoose' - -PrepaidSchema = new mongoose.Schema {}, {strict: false, minimize: false,read:'nearest'} +config = require '../../server_config' +PrepaidSchema = new mongoose.Schema {}, {strict: false, minimize: false,read:config.mongo.readpref} module.exports = Prepaid = mongoose.model('prepaid', PrepaidSchema) diff --git a/server/purchases/Purchase.coffee b/server/purchases/Purchase.coffee index 33a43c5b3..cb0c18130 100644 --- a/server/purchases/Purchase.coffee +++ b/server/purchases/Purchase.coffee @@ -1,6 +1,6 @@ mongoose = require('mongoose') - -PurchaseSchema = new mongoose.Schema({status: String}, {strict: false,read:'nearest'}) +config = require '../../server_config' +PurchaseSchema = new mongoose.Schema({status: String}, {strict: false,read:config.mongo.readpref}) PurchaseSchema.index({recipient: 1, 'purchased.original': 1}, {unique: true, name: 'unique purchase'}) module.exports = mongoose.model('purchase', PurchaseSchema) diff --git a/server/user_code_problems/UserCodeProblem.coffee b/server/user_code_problems/UserCodeProblem.coffee index dab0e8d34..e901a7705 100644 --- a/server/user_code_problems/UserCodeProblem.coffee +++ b/server/user_code_problems/UserCodeProblem.coffee @@ -1,10 +1,11 @@ mongoose = require 'mongoose' plugins = require '../plugins/plugins' +config = require '../../server_config' UserCodeProblemSchema = new mongoose.Schema({ created: type: Date 'default': Date.now -}, {strict: false,read:'nearest'}) +}, {strict: false,read:config.mongo.readpref}) module.exports = UserCodeProblem = mongoose.model('user.code.problem', UserCodeProblemSchema) diff --git a/server_config.coffee b/server_config.coffee index 48c82282e..c6825dbd6 100644 --- a/server_config.coffee +++ b/server_config.coffee @@ -20,6 +20,11 @@ config.mongo = mongoose_replica_string: process.env.COCO_MONGO_MONGOOSE_REPLICA_STRING or '' mongoose_tokyo_replica_string: process.env.COCO_MONGO_MONGOOSE_TOKYO_REPLICA_STRING or '' +if config.tokyo + config.mongo.readpref = 'nearest' +else + config.mongo.readpref = 'primary' + config.apple = verifyURL: process.env.COCO_APPLE_VERIFY_URL or 'https://sandbox.itunes.apple.com/verifyReceipt' diff --git a/server_setup.coffee b/server_setup.coffee index 3c47faa54..2ef442449 100644 --- a/server_setup.coffee +++ b/server_setup.coffee @@ -131,7 +131,7 @@ setupTrailingSlashRemovingMiddleware = (app) -> next() exports.setupMiddleware = (app) -> - #setupChinaRedirectMiddleware app + setupChinaRedirectMiddleware app setupMiddlewareToSendOldBrowserWarningWhenPlayersViewLevelDirectly app setupExpressMiddleware app setupPassportMiddleware app