diff --git a/examples/getstarted/config/environments/development/custom.json b/examples/getstarted/config/environments/development/custom.json
index bf59375e24..4e74ad71cd 100644
--- a/examples/getstarted/config/environments/development/custom.json
+++ b/examples/getstarted/config/environments/development/custom.json
@@ -1,3 +1,6 @@
{
- "myCustomConfiguration": "This configuration is accessible through strapi.config.environments.development.myCustomConfiguration"
+ "myCustomConfiguration": "This configuration is accessible through strapi.config.environments.development.myCustomConfiguration",
+ "public": {
+ "defaultIndex": false
+ }
}
diff --git a/packages/strapi-generate-new/lib/resources/files/public/index.html b/packages/strapi-generate-new/lib/resources/files/public/index.html
deleted file mode 100644
index 315cadcfbe..0000000000
--- a/packages/strapi-generate-new/lib/resources/files/public/index.html
+++ /dev/null
@@ -1,56 +0,0 @@
-
-
-
-
-
- Welcome to your Strapi app
-
-
-
-
-
-
-
-
-
- 
- <% if (isInitialised) { %>
-
- <% } %>
- <% if (!isInitialised) { %>
-
-
-
- <% } %>
-
-
-
-
-
diff --git a/packages/strapi-generate-new/lib/resources/files/public/production.html b/packages/strapi-generate-new/lib/resources/files/public/production.html
deleted file mode 100644
index f4b6bafa03..0000000000
--- a/packages/strapi-generate-new/lib/resources/files/public/production.html
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-
- Welcome to your Strapi app
-
-
-
-
-
-
-
-
-
- 
-
-
-
-
diff --git a/packages/strapi/lib/core/bootstrap.js b/packages/strapi/lib/core/bootstrap.js
index d779715400..3fc5ab04cc 100644
--- a/packages/strapi/lib/core/bootstrap.js
+++ b/packages/strapi/lib/core/bootstrap.js
@@ -9,13 +9,7 @@ const getKind = obj => obj.kind || 'collectionType';
const pickSchema = model => {
const schema = _.cloneDeep(
- _.pick(model, [
- 'connection',
- 'collectionName',
- 'info',
- 'options',
- 'attributes',
- ])
+ _.pick(model, ['connection', 'collectionName', 'info', 'options', 'attributes'])
);
schema.kind = getKind(model);
@@ -26,32 +20,25 @@ module.exports = function(strapi) {
// Retrieve Strapi version.
strapi.config.uuid = _.get(strapi.config.info, 'strapi.uuid', '');
strapi.config.info.customs = _.get(strapi.config.info, 'strapi', {});
- strapi.config.info.strapi = (
- _.get(strapi.config, 'info.dependencies.strapi') || ''
- ).replace(/(\^|~)/g, '');
+ strapi.config.info.strapi = (_.get(strapi.config, 'info.dependencies.strapi') || '').replace(
+ /(\^|~)/g,
+ ''
+ );
strapi.config.info.node = process.versions.node;
// Set connections.
strapi.connections = {};
// Set current environment config.
- strapi.config.currentEnvironment =
- strapi.config.environments[strapi.config.environment] || {};
+ strapi.config.currentEnvironment = strapi.config.environments[strapi.config.environment] || {};
- const defaultConnection =
- strapi.config.currentEnvironment.database.defaultConnection;
+ const defaultConnection = strapi.config.currentEnvironment.database.defaultConnection;
// Set current connections.
- strapi.config.connections = _.get(
- strapi.config.currentEnvironment,
- 'database.connections',
- {}
- );
+ strapi.config.connections = _.get(strapi.config.currentEnvironment, 'database.connections', {});
if (_.get(strapi.config, 'language.enabled')) {
- strapi.config.language.locales = Object.keys(
- _.get(strapi.config, 'locales', {})
- );
+ strapi.config.language.locales = Object.keys(_.get(strapi.config, 'locales', {}));
}
strapi.contentTypes = {};
@@ -71,8 +58,7 @@ module.exports = function(strapi) {
apiName,
modelName,
globalId: model.globalId || _.upperFirst(_.camelCase(modelName)),
- collectionName:
- model.collectionName || `${modelName}`.toLocaleLowerCase(),
+ collectionName: model.collectionName || `${modelName}`.toLocaleLowerCase(),
connection: model.connection || defaultConnection,
});
@@ -133,9 +119,7 @@ module.exports = function(strapi) {
modelName: key,
identity: model.identity || _.upperFirst(key),
globalId: model.globalId || _.upperFirst(_.camelCase(`admin-${key}`)),
- connection:
- model.connection ||
- strapi.config.currentEnvironment.database.defaultConnection,
+ connection: model.connection || strapi.config.currentEnvironment.database.defaultConnection,
});
strapi.contentTypes[model.uid] = model;
@@ -167,13 +151,9 @@ module.exports = function(strapi) {
modelName: key,
uid: `plugins::${pluginName}.${key}`,
plugin: pluginName,
- collectionName:
- model.collectionName || `${pluginName}_${key}`.toLowerCase(),
- globalId:
- model.globalId || _.upperFirst(_.camelCase(`${pluginName}-${key}`)),
- connection:
- model.connection ||
- strapi.config.currentEnvironment.database.defaultConnection,
+ collectionName: model.collectionName || `${pluginName}_${key}`.toLowerCase(),
+ globalId: model.globalId || _.upperFirst(_.camelCase(`${pluginName}-${key}`)),
+ connection: model.connection || strapi.config.currentEnvironment.database.defaultConnection,
});
strapi.contentTypes[model.uid] = model;
@@ -259,68 +239,54 @@ module.exports = function(strapi) {
}
// Preset config in alphabetical order.
- strapi.config.middleware.settings = Object.keys(strapi.middleware).reduce(
- (acc, current) => {
- // Try to find the settings in the current environment, then in the main configurations.
- const currentSettings = _.merge(
- _.get(
- _.cloneDeep(strapi.middleware[current]),
- ['defaults', current],
- {}
- ),
- flattenMiddlewaresConfig[current] ||
- strapi.config.currentEnvironment[current] ||
- strapi.config[current]
+ strapi.config.middleware.settings = Object.keys(strapi.middleware).reduce((acc, current) => {
+ // Try to find the settings in the current environment, then in the main configurations.
+ const currentSettings = _.merge(
+ _.get(_.cloneDeep(strapi.middleware[current]), ['defaults', current], {}),
+ strapi.config[current],
+ strapi.config.currentEnvironment[current],
+ flattenMiddlewaresConfig[current]
+ );
+ acc[current] = !_.isObject(currentSettings) ? {} : currentSettings;
+
+ if (!_.has(acc[current], 'enabled')) {
+ strapi.log.warn(
+ `(middleware:${current}) wasn't loaded due to missing key \`enabled\` in the configuration`
);
- acc[current] = !_.isObject(currentSettings) ? {} : currentSettings;
+ }
- if (!_.has(acc[current], 'enabled')) {
- strapi.log.warn(
- `(middleware:${current}) wasn't loaded due to missing key \`enabled\` in the configuration`
- );
- }
+ // Ensure that enabled key exist by forcing to false.
+ _.defaults(acc[current], { enabled: false });
- // Ensure that enabled key exist by forcing to false.
- _.defaults(acc[current], { enabled: false });
+ return acc;
+ }, {});
- return acc;
- },
- {}
- );
+ strapi.config.hook.settings = Object.keys(strapi.hook).reduce((acc, current) => {
+ // Try to find the settings in the current environment, then in the main configurations.
+ const currentSettings = _.merge(
+ _.get(_.cloneDeep(strapi.hook[current]), ['defaults', current], {}),
+ flattenHooksConfig[current] ||
+ _.get(strapi.config.currentEnvironment, ['hook', current]) ||
+ _.get(strapi.config, ['hook', current])
+ );
- strapi.config.hook.settings = Object.keys(strapi.hook).reduce(
- (acc, current) => {
- // Try to find the settings in the current environment, then in the main configurations.
- const currentSettings = _.merge(
- _.get(_.cloneDeep(strapi.hook[current]), ['defaults', current], {}),
- flattenHooksConfig[current] ||
- _.get(strapi.config.currentEnvironment, ['hook', current]) ||
- _.get(strapi.config, ['hook', current])
+ acc[current] = !_.isObject(currentSettings) ? {} : currentSettings;
+
+ if (!_.has(acc[current], 'enabled')) {
+ strapi.log.warn(
+ `(hook:${current}) wasn't loaded due to missing key \`enabled\` in the configuration`
);
+ }
- acc[current] = !_.isObject(currentSettings) ? {} : currentSettings;
+ // Ensure that enabled key exist by forcing to false.
+ _.defaults(acc[current], { enabled: false });
- if (!_.has(acc[current], 'enabled')) {
- strapi.log.warn(
- `(hook:${current}) wasn't loaded due to missing key \`enabled\` in the configuration`
- );
- }
-
- // Ensure that enabled key exist by forcing to false.
- _.defaults(acc[current], { enabled: false });
-
- return acc;
- },
- {}
- );
+ return acc;
+ }, {});
// default settings
- strapi.config.port =
- _.get(strapi.config.currentEnvironment, 'server.port') ||
- strapi.config.port;
- strapi.config.host =
- _.get(strapi.config.currentEnvironment, 'server.host') ||
- strapi.config.host;
+ strapi.config.port = _.get(strapi.config.currentEnvironment, 'server.port') || strapi.config.port;
+ strapi.config.host = _.get(strapi.config.currentEnvironment, 'server.host') || strapi.config.host;
// proxy settings
const proxy = _.get(strapi.config.currentEnvironment, 'server.proxy', {});
@@ -338,45 +304,24 @@ module.exports = function(strapi) {
port: strapi.config.port,
});
- const adminPath = _.get(
- strapi.config.currentEnvironment.server,
- 'admin.path',
- 'admin'
- );
+ const adminPath = _.get(strapi.config.currentEnvironment.server, 'admin.path', 'admin');
strapi.config.admin.url = new URL(adminPath, strapi.config.url).toString();
};
-const enableHookNestedDependencies = function(
- strapi,
- name,
- flattenHooksConfig,
- force = false
-) {
+const enableHookNestedDependencies = function(strapi, name, flattenHooksConfig, force = false) {
// Couldn't find configurations for this hook.
if (_.isEmpty(_.get(flattenHooksConfig, name, true))) {
// Check if database connector is used
- const modelsUsed = Object.keys(
- _.assign(_.clone(strapi.api) || {}, strapi.plugins)
- )
+ const modelsUsed = Object.keys(_.assign(_.clone(strapi.api) || {}, strapi.plugins))
.filter(x =>
- _.isObject(
- _.get(strapi.api, [x, 'models']) ||
- _.get(strapi.plugins, [x, 'models'])
- )
+ _.isObject(_.get(strapi.api, [x, 'models']) || _.get(strapi.plugins, [x, 'models']))
) // Filter API with models
- .map(
- x =>
- _.get(strapi.api, [x, 'models']) ||
- _.get(strapi.plugins, [x, 'models'])
- ) // Keep models
+ .map(x => _.get(strapi.api, [x, 'models']) || _.get(strapi.plugins, [x, 'models'])) // Keep models
.filter(models => {
const apiModelsUsed = Object.keys(models).filter(model => {
- const connector = _.get(
- strapi.config.connections,
- models[model].connection,
- {}
- ).connector;
+ const connector = _.get(strapi.config.connections, models[model].connection, {})
+ .connector;
if (connector) {
return connector.replace('strapi-hook-', '') === name;
diff --git a/examples/getstarted/public/index.html b/packages/strapi/lib/middlewares/public/index.html
similarity index 100%
rename from examples/getstarted/public/index.html
rename to packages/strapi/lib/middlewares/public/index.html
diff --git a/packages/strapi/lib/middlewares/public/index.js b/packages/strapi/lib/middlewares/public/index.js
index 99e8f54982..d64b068c41 100644
--- a/packages/strapi/lib/middlewares/public/index.js
+++ b/packages/strapi/lib/middlewares/public/index.js
@@ -17,6 +17,10 @@ const utils = require('../../utils');
* Public assets hook
*/
+const defaults = {
+ defaultIndex: true,
+};
+
module.exports = strapi => {
return {
/**
@@ -24,58 +28,19 @@ module.exports = strapi => {
*/
async initialize() {
- const { maxAge } = strapi.config.middleware.settings.public;
+ const { defaultIndex, maxAge } = Object.assign(
+ {},
+ defaults,
+ strapi.config.middleware.settings.public
+ );
const staticDir = path.resolve(
strapi.dir,
strapi.config.middleware.settings.public.path || strapi.config.paths.static
);
- const indexFileName = 'index.html';
- const indexPath = path.join(staticDir, indexFileName);
-
- if (fs.existsSync(indexPath)) {
- const index = fs.readFileSync(indexPath, 'utf8');
- const renderer = _.template(index); // Is the project initialized?
-
- const renderIndexPage = async () => {
- const isInitialised = await utils.isInitialised(strapi);
-
- const data = {
- serverTime: new Date().toUTCString(),
- isInitialised,
- ..._.pick(strapi, [
- 'config.info.version',
- 'config.info.name',
- 'config.admin.url',
- 'config.environment',
- ]),
- };
-
- return renderer(data);
- };
-
- const serveIndexPage = async ctx => {
- ctx.url = indexFileName;
-
- const content = await renderIndexPage();
- const body = stream.Readable({
- read() {
- this.push(Buffer.from(content));
- this.push(null);
- },
- });
- // Serve static.
- ctx.type = 'html';
- ctx.body = body;
- };
-
- // Serve /public index page.
- strapi.router.get('/', serveIndexPage);
- strapi.router.get(`/${indexFileName}`, serveIndexPage);
- }
// Match every route with an extension.
// The file without extension will not be served.
- // Note: This route could be override by the user.
+ // Note: This route can be overriden by the user.
strapi.router.get(
'/*',
async (ctx, next) => {
@@ -90,6 +55,38 @@ module.exports = strapi => {
})
);
+ if (defaultIndex) {
+ const index = fs.readFileSync(path.join(__dirname, 'index.html'), 'utf8');
+
+ const serveIndexPage = async ctx => {
+ ctx.url = 'index.html';
+ const isInitialised = await utils.isInitialised(strapi);
+ const data = {
+ serverTime: new Date().toUTCString(),
+ isInitialised,
+ ..._.pick(strapi, [
+ 'config.info.version',
+ 'config.info.name',
+ 'config.admin.url',
+ 'config.environment',
+ ]),
+ };
+ const content = _.template(index)(data);
+ const body = stream.Readable({
+ read() {
+ this.push(Buffer.from(content));
+ this.push(null);
+ },
+ });
+ // Serve static.
+ ctx.type = 'html';
+ ctx.body = body;
+ };
+
+ strapi.router.get('/', serveIndexPage);
+ strapi.router.get('/index.html', serveIndexPage);
+ }
+
if (!strapi.config.serveAdminPanel) return;
const basename = _.get(strapi.config.currentEnvironment.server, 'admin.path')
@@ -106,7 +103,7 @@ module.exports = strapi => {
await next();
},
koaStatic(buildDir, {
- index: indexFileName,
+ index: '/',
maxage: maxAge,
defer: false,
})