fixes miscellaneous bugs while initializing with no localization, globals, custom css

This commit is contained in:
James
2020-06-01 14:16:12 -04:00
parent 1fc9256ef8
commit 7d2b54e4a0
13 changed files with 81 additions and 62 deletions

View File

@@ -53,7 +53,6 @@ const CreateFirstUser = (props) => {
type: 'password',
required: true,
},
...userConfig.fields,
];
return (

View File

View File

@@ -9,9 +9,12 @@ const buildCollectionSchema = (collection, config, schemaOptions = {}) => {
schema.plugin(paginate)
.plugin(buildQueryPlugin)
.plugin(localizationPlugin, config.localization)
.plugin(autopopulate);
if (config.localization) {
schema.plugin(localizationPlugin, config.localization);
}
return schema;
};

View File

@@ -8,7 +8,6 @@ const mongooseHidden = require('mongoose-hidden')({
const passport = require('passport');
const passportLocalMongoose = require('passport-local-mongoose');
const LocalStrategy = require('passport-local').Strategy;
const AnonymousStrategy = require('passport-anonymous');
const jwtStrategy = require('../auth/strategies/jwt');
const apiKeyStrategy = require('../auth/strategies/apiKey');
const collectionRoutes = require('./routes');
@@ -133,7 +132,6 @@ function registerCollections() {
passport.use(`${AuthCollection.config.slug}-jwt`, jwtStrategy(this.config, AuthCollection));
passport.serializeUser(AuthCollection.Model.serializeUser());
passport.deserializeUser(AuthCollection.Model.deserializeUser());
passport.use(new AnonymousStrategy.Strategy());
this.router.use(authRoutes(AuthCollection, this.config, this.sendEmail));
} else {

View File

@@ -1,5 +1,6 @@
const express = require('express');
const passport = require('passport');
const AnonymousStrategy = require('passport-anonymous');
const compression = require('compression');
const bodyParser = require('body-parser');
const methodOverride = require('method-override');
@@ -10,6 +11,8 @@ const authenticate = require('./authenticate');
const identifyAPI = require('./identifyAPI');
const middleware = (config) => {
passport.use(new AnonymousStrategy.Strategy());
return [
passport.initialize(),
passport.session(),

View File

@@ -6,46 +6,48 @@ const {
} = require('./resolvers');
function registerGlobals() {
Object.keys(this.globals.config).forEach((slug) => {
const global = this.globals.config[slug];
const {
label,
fields,
} = global;
if (this.config.globals) {
Object.keys(this.globals.config).forEach((slug) => {
const global = this.globals.config[slug];
const {
label,
fields,
} = global;
const formattedLabel = formatName(label);
const formattedLabel = formatName(label);
global.graphQL = {};
global.graphQL = {};
global.graphQL.type = this.buildObjectType(
formattedLabel,
fields,
formattedLabel,
);
global.graphQL.type = this.buildObjectType(
formattedLabel,
fields,
formattedLabel,
);
global.graphQL.mutationInputType = new GraphQLNonNull(this.buildMutationInputType(
formattedLabel,
fields,
formattedLabel,
));
global.graphQL.mutationInputType = new GraphQLNonNull(this.buildMutationInputType(
formattedLabel,
fields,
formattedLabel,
));
this.Query.fields[formattedLabel] = {
type: global.graphQL.type,
args: {
locale: { type: this.types.localeInputType },
fallbackLocale: { type: this.types.fallbackLocaleInputType },
},
resolve: findOne(this.globals.Model, global),
};
this.Query.fields[formattedLabel] = {
type: global.graphQL.type,
args: {
locale: { type: this.types.localeInputType },
fallbackLocale: { type: this.types.fallbackLocaleInputType },
},
resolve: findOne(this.globals.Model, global),
};
this.Mutation.fields[`update${formattedLabel}`] = {
type: global.graphQL.type,
args: {
data: { type: global.graphQL.mutationInputType },
},
resolve: update(this.globals.Model, global),
};
});
this.Mutation.fields[`update${formattedLabel}`] = {
type: global.graphQL.type,
args: {
data: { type: global.graphQL.mutationInputType },
},
resolve: update(this.globals.Model, global),
};
});
}
}
module.exports = registerGlobals;

View File

@@ -3,9 +3,9 @@ const sanitize = require('./sanitize');
const routes = require('./routes');
function initGlobals() {
this.config.globals = sanitize(this.config.globals);
if (this.config.globals) {
this.config.globals = sanitize(this.config.globals);
this.globals = {
Model: buildModel(this.config),
config: this.config.globals,

View File

@@ -20,10 +20,13 @@ class GraphQL {
this.types = {
blockTypes: {},
blockInputTypes: {},
localeInputType: buildLocaleInputType(this.config.localization),
fallbackLocaleInputType: buildFallbackLocaleInputType(this.config.localization),
};
if (this.config.localization) {
this.types.localeInputType = buildLocaleInputType(this.config.localization);
this.types.fallbackLocaleInputType = buildFallbackLocaleInputType(this.config.localization);
}
this.Query = {
name: 'Query',
fields: {},

View File

@@ -23,6 +23,9 @@ class Payload {
const config = getConfig(options);
this.config = sanitizeConfig(config);
if (typeof this.config.paths === 'undefined') this.config.paths = {};
this.config.paths.publicConfig = options.config.public;
this.express = options.express;

View File

@@ -6,26 +6,28 @@
*/
module.exports = function localizationMiddleware(localization) {
const middleware = (req, res, next) => {
const validLocales = [...localization.locales, 'all'];
const validFallbackLocales = [...localization.locales, 'null'];
if (localization) {
const validLocales = [...localization.locales, 'all'];
const validFallbackLocales = [...localization.locales, 'null'];
let requestedLocale = req.query.locale || localization.defaultLocale;
let requestedFallbackLocale = req.query['fallback-locale'] || localization.defaultLocale;
let requestedLocale = req.query.locale || localization.defaultLocale;
let requestedFallbackLocale = req.query['fallback-locale'] || localization.defaultLocale;
if (req.body) {
if (req.body.locale) requestedLocale = req.body.locale;
if (req.body['fallback-locale']) requestedFallbackLocale = req.body['fallback-locale'];
}
if (req.body) {
if (req.body.locale) requestedLocale = req.body.locale;
if (req.body['fallback-locale']) requestedFallbackLocale = req.body['fallback-locale'];
}
if (requestedFallbackLocale === 'none') requestedFallbackLocale = 'null';
if (requestedLocale === '*' || requestedLocale === 'all') requestedLocale = 'all';
if (requestedFallbackLocale === 'none') requestedFallbackLocale = 'null';
if (requestedLocale === '*' || requestedLocale === 'all') requestedLocale = 'all';
if (validLocales.find(locale => locale === requestedLocale)) {
req.locale = requestedLocale;
}
if (validLocales.find(locale => locale === requestedLocale)) {
req.locale = requestedLocale;
}
if (validFallbackLocales.find(locale => locale === requestedFallbackLocale)) {
req.fallbackLocale = requestedFallbackLocale;
if (validFallbackLocales.find(locale => locale === requestedFallbackLocale)) {
req.fallbackLocale = requestedFallbackLocale;
}
}
return next();

View File

@@ -7,6 +7,8 @@ const sanitizeConfig = (config) => {
if (!sanitizedConfig.cookiePrefix) sanitizedConfig.cookiePrefix = 'payload';
if (!sanitizedConfig.globals) sanitizedConfig.globals = [];
if (!sanitizedConfig.admin.user) {
sanitizedConfig.admin.user = config.admin.user || 'users';

View File

@@ -4,10 +4,8 @@ const webpack = require('webpack');
const getStyleLoaders = require('./getStyleLoaders');
const secureConfig = require('../utilities/secureConfig');
const dependency = 'fuck';
module.exports = (config) => {
return {
const webpackConfig = {
entry: {
main: [
path.resolve(__dirname, '../../node_modules/webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000'),
@@ -118,8 +116,15 @@ module.exports = (config) => {
modules: ['node_modules', path.resolve(__dirname, '../../node_modules')],
alias: {
'payload/config': config.paths.publicConfig,
'payload-scss-overrides': config.paths.scss,
},
},
};
if (config.paths.scss) {
webpackConfig.resolve.alias['payload-scss-overrides'] = config.paths.scss;
} else {
webpackConfig.resolve.alias['payload-scss-overrides'] = path.resolve(__dirname, '../client/scss/overrides.scss');
}
return webpackConfig;
};