Skip to content

Commit d23a138

Browse files
committed
chore(config): freeze configuration object
Remove const assignements to config keys closes #12
1 parent 9f70367 commit d23a138

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/configManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ConfigManager {
4343
options.adminPath = options.adminPath.replace(/\/?$/, "/");
4444
options.extensionsDir = join(nuxtOptions.srcDir, options.extensionsDir);
4545
options.buildDir = join(nuxtOptions.buildDir, "dist", options.adminPath);
46-
this._config = options;
46+
this._config = Object.freeze(options);
4747
}
4848

4949
get config() {

src/module.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ export default function NetlifyCmsModule(moduleOptions) {
2626
const configManager = new ConfigManager(this.options, moduleOptions);
2727
const config = configManager.config;
2828

29-
const ADMIN_PATH = config.adminPath;
30-
const BUILD_DIR = config.buildDir;
31-
3229
// This will be called once when builder started
3330
this.nuxt.plugin("build", async builder => {
3431
// This will be run just before webpack compiler starts
@@ -79,7 +76,7 @@ export default function NetlifyCmsModule(moduleOptions) {
7976
if (this.options.dev) {
8077
// Show a message inside console when the build is ready
8178
builder.plugin("compiled", async () => {
82-
debug(`Serving on: ${ADMIN_PATH}`);
79+
debug(`Serving on: ${config.adminPath}`);
8380
});
8481

8582
// Create webpack dev middleware
@@ -119,10 +116,10 @@ export default function NetlifyCmsModule(moduleOptions) {
119116
if (this.options.dev) {
120117
// Insert webpackDevMiddleware to serve netlify CMS in development
121118
this.addServerMiddleware({
122-
path: ADMIN_PATH,
119+
path: config.adminPath,
123120
handler: async (req, res) => {
124121
if (this.nuxt.renderer.netlifyWebpackDevMiddleware) {
125-
debug(`requesting url: ${Utils.urlJoin(ADMIN_PATH, req.url)}`);
122+
debug(`requesting url: ${Utils.urlJoin(config.adminPath, req.url)}`);
126123
await this.nuxt.renderer.netlifyWebpackDevMiddleware(req, res);
127124
}
128125
if (this.nuxt.renderer.netlifyWebpackHotMiddleware) {
@@ -163,8 +160,8 @@ export default function NetlifyCmsModule(moduleOptions) {
163160
} else {
164161
// Statically serve netlify CMS (i.e. .nuxt/dist/admin/) files in production
165162
this.addServerMiddleware({
166-
path: ADMIN_PATH,
167-
handler: serveStatic(BUILD_DIR, {
163+
path: config.adminPath,
164+
handler: serveStatic(config.buildDir, {
168165
maxAge: "1y" // 1 year in production
169166
})
170167
});

0 commit comments

Comments
 (0)