remove old module.exports from server aswell

This commit is contained in:
Matteo Pagliazzi
2019-10-02 19:45:27 +02:00
parent e0a2528a4f
commit 45f7cf04ab
91 changed files with 116 additions and 127 deletions

View File

@@ -432,4 +432,4 @@ api.deleteSocial = {
},
};
module.exports = api;
export default api;

View File

@@ -827,4 +827,4 @@ api.cloneChallenge = {
},
};
module.exports = api;
export default api;

View File

@@ -542,4 +542,4 @@ api.deleteChat = {
},
};
module.exports = api;
export default api;

View File

@@ -135,4 +135,4 @@ api.getContent = {
},
};
module.exports = api;
export default api;

View File

@@ -137,4 +137,4 @@ api.validateCoupon = {
},
};
module.exports = api;
export default api;

View File

@@ -19,4 +19,4 @@ api.cron = {
},
};
module.exports = api;
export default api;

View File

@@ -198,4 +198,4 @@ api.questProgress = {
},
};
module.exports = api;
export default api;

View File

@@ -1217,4 +1217,4 @@ api.getGroupPlans = {
},
};
module.exports = api;
export default api;

View File

@@ -302,4 +302,4 @@ api.updateHero = {
},
};
module.exports = api;
export default api;

View File

@@ -43,4 +43,4 @@ api.geti18nBrowserScript = {
},
};
module.exports = api;
export default api;

View File

@@ -1,4 +1,5 @@
// NOTE: this file is only used because the mobile apps expect IAP routes
// to be found at /api/v3/iap instead of /iap.
module.exports = require('../top-level/payments/iap');
import iap from '../top-level/payments/iap';
export default iap;

View File

@@ -33,4 +33,4 @@ api.getInboxMessages = {
},
};
module.exports = api;
export default api;

View File

@@ -737,4 +737,4 @@ api.transferGems = {
};
module.exports = api;
export default api;

View File

@@ -51,4 +51,4 @@ api.getModelPaths = {
},
};
module.exports = api;
export default api;

View File

@@ -87,4 +87,4 @@ api.tellMeLaterNews = {
},
};
module.exports = api;
export default api;

View File

@@ -191,4 +191,4 @@ api.seeNotifications = {
},
};
module.exports = api;
export default api;

View File

@@ -103,4 +103,4 @@ api.removePushDevice = {
},
};
module.exports = api;
export default api;

View File

@@ -513,4 +513,4 @@ api.leaveQuest = {
},
};
module.exports = api;
export default api;

View File

@@ -142,4 +142,4 @@ api.getBackgroundShopItems = {
},
};
module.exports = api;
export default api;

View File

@@ -22,4 +22,4 @@ api.getStatus = {
},
};
module.exports = api;
export default api;

View File

@@ -246,4 +246,4 @@ api.deleteTag = {
},
};
module.exports = api;
export default api;

View File

@@ -1356,4 +1356,4 @@ api.deleteTask = {
},
};
module.exports = api;
export default api;

View File

@@ -541,4 +541,4 @@ api.getGroupApprovals = {
},
};
module.exports = api;
export default api;

View File

@@ -1689,4 +1689,4 @@ api.movePinnedItem = {
},
};
module.exports = api;
export default api;

View File

@@ -65,4 +65,4 @@ api.castSpell = {
},
};
module.exports = api;
export default api;

View File

@@ -134,4 +134,4 @@ api.allocateNow = {
},
};
module.exports = api;
export default api;

View File

@@ -222,4 +222,4 @@ api.deleteWebhook = {
},
};
module.exports = api;
export default api;

View File

@@ -43,4 +43,4 @@ api.getWorldState = {
},
};
module.exports = api;
export default api;

View File

@@ -78,4 +78,4 @@ api.registerLocal = {
},
};
module.exports = api;
export default api;

View File

@@ -31,4 +31,4 @@ api.enterCouponCode = {
},
};
module.exports = api;
export default api;

View File

@@ -135,4 +135,4 @@ api.getInboxMessages = {
},
};
module.exports = api;
export default api;

View File

@@ -40,4 +40,4 @@ api.flagPrivateMessage = {
},
};
module.exports = api;
export default api;

View File

@@ -235,4 +235,4 @@ api.verifyDisplayName = {
},
};
module.exports = api;
export default api;

View File

@@ -71,4 +71,4 @@ api.castSpell = {
},
};
module.exports = api;
export default api;

View File

@@ -32,4 +32,4 @@ api.logout = {
},
};
module.exports = api;
export default api;

View File

@@ -343,4 +343,4 @@ api.exportUserPrivateMessages = {
},
};
module.exports = api;
export default api;

View File

@@ -54,4 +54,4 @@ api.unsubscribe = {
},
};
module.exports = api;
export default api;

View File

@@ -16,4 +16,4 @@ api.getNewClient = {
},
};
module.exports = api;
export default api;

View File

@@ -142,4 +142,4 @@ api.subscribeCancel = {
},
};
module.exports = api;
export default api;

View File

@@ -192,4 +192,4 @@ api.iapSubscriptioniOSNoRenew = {
},
};
module.exports = api;
export default api;

View File

@@ -170,4 +170,4 @@ api.ipn = {
},
};
module.exports = api;
export default api;

View File

@@ -98,4 +98,4 @@ api.handleWebhooks = {
},
};
module.exports = api;
export default api;

View File

@@ -14,4 +14,4 @@ api.redirectProfileQRCode = {
},
};
module.exports = api;
export default api;

View File

@@ -8,7 +8,7 @@ if (process.env.NODE_ENV !== 'production') {
}
// Initialize configuration BEFORE anything
const setupNconf = require('./libs/setupNconf');
const setupNconf = require('./libs/setupNconf').default;
setupNconf();
const nconf = require('nconf');

View File

@@ -320,7 +320,7 @@ const mockAnalyticsService = {
trackPurchase: () => { },
};
module.exports = {
export {
track,
trackPurchase,
mockAnalyticsService,

View File

@@ -205,7 +205,7 @@ async function registerLocal (req, res, { isV3 = false }) {
return null;
}
module.exports = {
export {
loginRes,
hasBackupAuth,
hasLocalAuth,

View File

@@ -21,7 +21,7 @@ function _passportProfile (network, accessToken) {
});
}
async function loginSocial (req, res) {
export async function loginSocial (req, res) {
const existingUser = res.locals.user;
const accessToken = req.body.authResponse.access_token;
const network = req.body.network;
@@ -111,7 +111,3 @@ async function loginSocial (req, res) {
return null;
}
module.exports = {
loginSocial,
};

View File

@@ -6,12 +6,12 @@ import { NotAuthorized } from '../errors';
const COMMUNITY_MANAGER_EMAIL = nconf.get('EMAILS_COMMUNITY_MANAGER_EMAIL');
const translator = shortid('0123456789abcdefghijklmnopqrstuvwxyz');
function generateUsername () {
export function generateUsername () {
let newName = `hb-${translator.new()}`;
return newName.substring(0, 20);
}
function loginRes (user, req, res) {
export function loginRes (user, req, res) {
if (user.auth.blocked) throw new NotAuthorized(res.t('accountSuspended', {communityManagerEmail: COMMUNITY_MANAGER_EMAIL, userId: user._id}));
const responseData = {
@@ -23,8 +23,3 @@ function loginRes (user, req, res) {
return res.respond(200, responseData);
}
module.exports = {
generateUsername,
loginRes,
};

View File

@@ -84,7 +84,7 @@
// DO NOT EDIT! See the comments at the top of this file.
let bannedSlurs = [
const bannedSlurs = [
'TESTPLACEHOLDERSLURWORDHERE',
'TESTPLACEHOLDERSLURWORDHERE1',
@@ -110,4 +110,4 @@ let bannedSlurs = [
'cunts',
];
module.exports = bannedSlurs;
export default bannedSlurs;

View File

@@ -174,4 +174,4 @@ let bannedWords = [
'pewdiepie',
];
module.exports = bannedWords;
export default bannedWords;

View File

@@ -2,7 +2,7 @@ import { v4 as uuid } from 'uuid';
import validator from 'validator';
import _ from 'lodash';
module.exports = function baseModel (schema, options = {}) {
export default function baseModel (schema, options = {}) {
if (schema.options.typeKey !== '$type') {
throw new Error('Every schema must use $type as the typeKey, see https://mongoosejs.com/docs/guide.html#typeKey');
}
@@ -79,4 +79,4 @@ module.exports = function baseModel (schema, options = {}) {
return result;
}, {});
};
};
}

View File

@@ -1,6 +1,6 @@
import csvStringify from 'csv-stringify';
module.exports = (input) => {
export default (input) => {
return new Promise((resolve, reject) => {
csvStringify(input, (err, output) => {
if (err) return reject(err);

View File

@@ -1,7 +1,7 @@
/* eslint-disable no-multiple-empty-lines */
// This file contains usernames that we do not want users to use, because they give the account more legitimacy and may deceive users.
let bannedWords = [
const bannedWords = [
'TESTPLACEHOLDERSWEARWORDHERE',
'TESTPLACEHOLDERSWEARWORDHERE1',
@@ -17,4 +17,4 @@ let bannedWords = [
'gryphon',
];
module.exports = bannedWords;
export default bannedWords;

View File

@@ -8,7 +8,7 @@
// This is for a short-term, partial solution to the need for swearword blocking in guilds.
// Later, it will be replaced with customised lists of disallowed words based on the guilds' tags.
let guildsAllowingBannedWords = {
const guildsAllowingBannedWords = {
'f646bc11-e330-482c-982a-843cd018373c': true, // Abuse Victims and Survivors
'b5843474-07e6-4af2-9bd0-b8a00fe7fe52': true, // Alcoholics Anonymous - One Day at a Time!
'd3339c3d-6744-4c17-b9d3-a16bdcfb5d53': true, // Am Yisrael Chai
@@ -140,4 +140,4 @@ let guildsAllowingBannedWords = {
'14ae3965-0536-4b63-bc55-3dbd6660e3af': true, // Purely Positive Dog Trainers
};
module.exports = guildsAllowingBannedWords;
export default guildsAllowingBannedWords;

View File

@@ -17,7 +17,7 @@ iap.config({
applePassword: nconf.get('ITUNES_SHARED_SECRET'),
});
module.exports = {
export default {
setup: util.promisify(iap.setup.bind(iap)),
validate: util.promisify(iap.validate.bind(iap)),
isValidated: iap.isValidated,

View File

@@ -204,7 +204,7 @@ async function inviteByUserName (username, group, inviter, req, res) {
return await addInvitationToUser(userToInvite, group, inviter, res);
}
module.exports = {
export {
inviteByUUID,
inviteByEmail,
inviteByUserName,

View File

@@ -89,4 +89,4 @@ process.on('unhandledRejection', function handlePromiseRejection (reason, p) {
loggerInterface.error(reason, 'unhandledPromiseRejection at', p);
});
module.exports = loggerInterface;
export default loggerInterface;

View File

@@ -344,4 +344,4 @@ api.chargeForAdditionalGroupMember = async function chargeForAdditionalGroupMemb
});
};
module.exports = api;
export default api;

View File

@@ -269,4 +269,4 @@ api.cancelSubscribe = async function cancelSubscribe (user, headers) {
};
module.exports = api;
export default api;

View File

@@ -94,4 +94,4 @@ async function buyGems (data) {
await data.user.save();
}
module.exports = { buyGems };
export { buyGems };

View File

@@ -248,4 +248,4 @@ api.cancelSubscribe = async function cancelSubscribe (user, headers) {
};
module.exports = api;
export default api;

View File

@@ -235,7 +235,7 @@ async function cancelGroupSubscriptionForUser (user, group, userWasRemoved = fal
}
}
module.exports = {
export {
addSubscriptionToGroupUsers,
addSubToGroupUser,
cancelGroupUsersSubscription,

View File

@@ -36,4 +36,4 @@ api.cancelSubscription = cancelSubscription;
api.buyGems = buyGems;
module.exports = api;
export default api;

View File

@@ -288,4 +288,4 @@ api.ipn = async function ipnApi (options = {}) {
}
};
module.exports = api;
export default api;

View File

@@ -235,4 +235,4 @@ api.handleWebhooks = async function handleWebhooks (options, stripeInc) {
};
module.exports = api;
export default api;

View File

@@ -11,4 +11,4 @@ function getStripeApi () {
return stripe;
}
module.exports = { getStripeApi, setStripeApi };
export { getStripeApi, setStripeApi };

View File

@@ -143,4 +143,4 @@ async function checkout (options, stripeInc) {
await applyGemPayment(user, response, gift);
}
module.exports = { checkout };
export { checkout };

View File

@@ -1,4 +1,4 @@
module.exports = {
export default {
// CURRENCY_CODE: 'USD',
// SELLER_NOTE: 'Habitica Payment',
// SELLER_NOTE_SUBSCRIPTION: 'Habitica Subscription',

View File

@@ -316,7 +316,7 @@ async function cancelSubscription (data) {
});
}
module.exports = {
export {
createSubscription,
cancelSubscription,
};

View File

@@ -80,6 +80,6 @@ function sendNotification (user, details = {}) {
});
}
module.exports = {
export {
sendNotification,
};

View File

@@ -9,7 +9,7 @@ import {
let _wrapAsyncFn = fn => (...args) => fn(...args).catch(args[2]);
let noop = (req, res, next) => next();
module.exports.readController = function readController (router, controller, overrides = []) {
export function readController (router, controller, overrides = []) {
_.each(controller, (action) => {
let {method, url, middlewares = [], handler} = action;
@@ -45,17 +45,17 @@ module.exports.readController = function readController (router, controller, ove
router[method](url, ...middlewares, fn);
});
};
}
module.exports.walkControllers = function walkControllers (router, filePath, overrides) {
export function walkControllers (router, filePath, overrides) {
fs
.readdirSync(filePath)
.forEach(fileName => {
if (!fs.statSync(filePath + fileName).isFile()) {
walkControllers(router, `${filePath}${fileName}/`, overrides);
} else if (fileName.match(/\.js$/)) {
let controller = require(filePath + fileName); // eslint-disable-line global-require
module.exports.readController(router, controller, overrides);
let controller = require(filePath + fileName).default; // eslint-disable-line global-require
readController(router, controller, overrides);
}
});
};
}

View File

@@ -4,7 +4,7 @@ const { join, resolve } = require('path');
const PATH_TO_CONFIG = join(resolve(__dirname, '../../../config.json'));
module.exports = function setupNconf (file) {
export default function setupNconf (file) {
let configFile = file || PATH_TO_CONFIG;
nconf
@@ -15,4 +15,4 @@ module.exports = function setupNconf (file) {
nconf.set('IS_PROD', nconf.get('NODE_ENV') === 'production');
nconf.set('IS_DEV', nconf.get('NODE_ENV') === 'development');
nconf.set('IS_TEST', nconf.get('NODE_ENV') === 'test');
};
}

View File

@@ -282,7 +282,7 @@ function sendSlurNotification ({
});
}
module.exports = {
export {
sendFlagNotification,
sendInboxFlagNotification,
sendSubscriptionNotification,

View File

@@ -16,8 +16,8 @@ if (nconf.get('IS_PROD')) {
service = mockAnalyticsService;
}
module.exports = function attachAnalytics (req, res, next) {
export default function attachAnalytics (req, res, next) {
res.analytics = service;
next();
};
}

View File

@@ -2,7 +2,7 @@ import express from 'express';
import expressValidator from 'express-validator';
import analytics from './analytics';
import setupBody from './setupBody';
import routes from '../libs/routes';
import * as routes from '../libs/routes';
import path from 'path';
const API_V3_CONTROLLERS_PATH = path.join(__dirname, '/../controllers/api-v3/');
@@ -51,4 +51,4 @@ routes.walkControllers(v4Router, API_V3_CONTROLLERS_PATH, v4RouterOverrides);
routes.walkControllers(v4Router, API_V4_CONTROLLERS_PATH);
app.use('/api/v4', v4Router);
module.exports = app;
export default app;

View File

@@ -1,4 +1,4 @@
module.exports = function corsMiddleware (req, res, next) {
export default function corsMiddleware (req, res, next) {
res.set({
'Access-Control-Allow-Origin': req.header('origin') || '*',
'Access-Control-Allow-Methods': 'OPTIONS,GET,POST,PUT,HEAD,DELETE',
@@ -6,4 +6,4 @@ module.exports = function corsMiddleware (req, res, next) {
});
if (req.method === 'OPTIONS') return res.sendStatus(200);
return next();
};
}

View File

@@ -160,10 +160,10 @@ async function cronAsync (req, res) {
}
}
module.exports = function cronMiddleware (req, res, next) {
export default function cronMiddleware (req, res, next) {
cronAsync(req, res)
.then(() => {
next();
})
.catch(next);
};
}

View File

@@ -1,6 +1,6 @@
import domainMiddleware from 'domain-middleware';
module.exports = function implementDomainMiddleware (server, mongoose) {
export default function implementDomainMiddleware (server, mongoose) {
return domainMiddleware({
server: {
close () {
@@ -10,4 +10,4 @@ module.exports = function implementDomainMiddleware (server, mongoose) {
},
killTimeout: 10000,
});
};
}

View File

@@ -3,10 +3,10 @@ import {
NotFound,
} from '../libs/errors';
module.exports = function ensureDevelpmentMode (req, res, next) {
export default function ensureDevelpmentMode (req, res, next) {
if (nconf.get('IS_PROD')) {
next(new NotFound());
} else {
next();
}
};
}

View File

@@ -11,7 +11,7 @@ import {
omit,
} from 'lodash';
module.exports = function errorHandler (err, req, res, next) { // eslint-disable-line no-unused-vars
export default function errorHandler (err, req, res, next) { // eslint-disable-line no-unused-vars
// In case of a CustomError class, use it's data
// Otherwise try to identify the type of error (mongoose validation, mongodb unique, ...)
// If we can't identify it, respond with a generic 500 error
@@ -91,4 +91,4 @@ module.exports = function errorHandler (err, req, res, next) { // eslint-disable
// In some occasions like when invalid JSON is supplied `res.respond` might be not yet avalaible,
// in this case we use the standard res.status(...).json(...)
return res.status(responseErr.httpCode).json(jsonRes);
};
}

View File

@@ -37,7 +37,7 @@ const ENABLE_HTTP_AUTH = nconf.get('SITE_HTTP_AUTH_ENABLED') === 'true';
const SESSION_SECRET = nconf.get('SESSION_SECRET');
const TEN_YEARS = 1000 * 60 * 60 * 24 * 365 * 10;
module.exports = function attachMiddlewares (app, server) {
export default function attachMiddlewares (app, server) {
app.set('view engine', 'pug');
app.set('views', `${__dirname}/../../views`);
@@ -104,4 +104,4 @@ module.exports = function attachMiddlewares (app, server) {
// Error handler middleware, define as the last one.
app.use(errorHandler);
};
}

View File

@@ -3,7 +3,7 @@ import nconf from 'nconf';
const MAINTENANCE_MODE = nconf.get('MAINTENANCE_MODE');
module.exports = function maintenanceMode (req, res, next) {
export default function maintenanceMode (req, res, next) {
if (MAINTENANCE_MODE !== 'true') return next();
getUserLanguage(req, res, (err) => {
@@ -28,4 +28,4 @@ module.exports = function maintenanceMode (req, res, next) {
});
}
});
};
}

View File

@@ -18,7 +18,7 @@ const TOP_LEVEL_ROUTES = [
// handler because they don't have any child route
];
module.exports = function NotFoundMiddleware (req, res, next) {
export default function NotFoundMiddleware (req, res, next) {
const reqUrl = req.originalUrl;
const isExistingRoute = TOP_LEVEL_ROUTES.find(routeRoot => {
@@ -31,4 +31,4 @@ module.exports = function NotFoundMiddleware (req, res, next) {
} else {
serveClient(res);
}
};
}

View File

@@ -3,7 +3,7 @@ import {
model as UserNotification,
} from '../models/userNotification';
module.exports = function responseHandler (req, res, next) {
export default function responseHandler (req, res, next) {
// Only used for successful responses
res.respond = function respond (status = 200, data = {}, message) {
let user = res.locals && res.locals.user;
@@ -26,4 +26,4 @@ module.exports = function responseHandler (req, res, next) {
};
next();
};
}

View File

@@ -1,5 +1,5 @@
// TODO test this middleware
module.exports = function setupBodyMiddleware (req, res, next) {
export default function setupBodyMiddleware (req, res, next) {
req.body = req.body || {};
next();
};
}

View File

@@ -6,7 +6,7 @@ const IS_PROD = nconf.get('IS_PROD');
const MAX_AGE = IS_PROD ? 31536000000 : 0;
const BASE_DIR = path.join(__dirname, '/../../..');
module.exports = function staticMiddleware (expressApp) {
export default function staticMiddleware (expressApp) {
// Expose static files for new client
expressApp.use('/static/js', express.static(`${BASE_DIR}/dist-client/static/js`, { maxAge: MAX_AGE }));
expressApp.use('/static/css', express.static(`${BASE_DIR}/dist-client/static/css`, { maxAge: MAX_AGE }));
@@ -20,4 +20,4 @@ module.exports = function staticMiddleware (expressApp) {
// Apidoc
expressApp.use('/apidoc', express.static(`${BASE_DIR}/apidoc_build`));
};
}

View File

@@ -16,4 +16,4 @@ router.all('*', function deprecatedV1 (req, res, next) {
return next(error);
});
module.exports = router;
export default router;

View File

@@ -16,4 +16,4 @@ router.all('*', function deprecatedV2 (req, res, next) {
return next(error);
});
module.exports = router;
export default router;

View File

@@ -56,5 +56,4 @@ schema.statics.apply = async function applyCoupon (user, req, code) {
await coupon.save();
};
module.exports.schema = schema;
export let model = mongoose.model('Coupon', schema);

View File

@@ -19,7 +19,7 @@ const Schema = mongoose.Schema;
const RESTRICTED_EMAIL_DOMAINS = Object.freeze(['habitica.com', 'habitrpg.com']);
// User schema definition
let schema = new Schema({
export default new Schema({
apiToken: {
$type: String,
default: shared.uuid,
@@ -613,6 +613,4 @@ let schema = new Schema({
strict: true,
minimize: false, // So empty objects are returned
typeKey: '$type', // So that we can use fields named `type`
});
module.exports = schema;
});

View File

@@ -30,4 +30,4 @@ server.listen(app.get('port'), () => {
logger.info(`Express server listening on port ${app.get('port')}`);
});
module.exports = server;
export default server;