Repository navigation
enhance configurabiltiy of paths & make execution path-independent - #940
Conversation
1d476d4 to
8d9b30c
Compare
SISheogorath
left a comment
There was a problem hiding this comment.
Some minor changes :)
|
|
||
| function createDmpWorker () { | ||
| var worker = childProcess.fork('./lib/workers/dmpWorker.js', { | ||
| var worker = childProcess.fork(path.join(__dirname, '../workers/dmpWorker.js'), { |
There was a problem hiding this comment.
Can we use path.resolve() here as well? I see no point in not using resolve everywhere.
| | `prettyPath` | `./public/views/pretty.ejs` | pretty template file path | | ||
| | `slidePath` | `./public/views/slide.hbs` | slide template file path | | ||
| | `uploadsPath` | `./public/uploads` | uploads directory - needs to be persistent when you use imageUploadType `filesystem` | | ||
| | `sslKeyPath` | `./cert/client.key` | SSL key path (only need when you set `useSSL`, Note: relative paths are based on CodiMDs base directory) | |
There was a problem hiding this comment.
Not sure if we explicitly need to point out this everywhere. From my perspective this can be expected. @ccoenen you as someone who has a good point of view on usability, what do you think about this?
There was a problem hiding this comment.
I agree that this is very exhaustive, I intentionally added a note to each option so that no false interpretations happen when there is just a note for one of the options. Maybe a footnote in combination with a reference to it at each relative path makes more sense. :)
There was a problem hiding this comment.
Maybe we should split out the file options anyway. Would like to move them to an own document in the docs/ section. They are basically not needed by most users and the people who want to use them, should be able to find them in the docs/ section
There was a problem hiding this comment.
@SISheogorath So I just changed my note from being a inline comment for each option to a reference of a footnote and rebased onto master.
While I do agree with you on moving parts of the README to a separate file in docs/, I think that it is out of scope for this PR. I'd to open an issue for restructuring the documentation if that is okay with you. (Edit: just found #334). I might even work on it myself in the future, but not in the next days :)
| } | ||
|
|
||
| const configFilePath = path.join(appRootPath, 'config.json') | ||
| const configFilePath = process.env.CMD_CONFIG_FILE || path.join(appRootPath, 'config.json') |
There was a problem hiding this comment.
We should use also use path.resolve here. And then put it like this:
const configFilePath = path.resolve(appRootPath, process.env.CMD_CONFIG_FILE || './config.json')
Seems more intuitive to me. Even when I'm still not happy with having two locations where we resolve environment variables now .-.
8d9b30c to
1522a52
Compare
b92c51f to
d0cce34
Compare
|
@SISheogorath a few days ago I realized that there is still something missing here but I haven't had much time until now. So basically the current state of this PR doesn't have any negative impact when the configurable paths aren't used, but it also doesn't work properly so far. While the configurable diff --git a/app.js b/app.js
index 24f0516..eef77f0 100644
--- a/app.js
+++ b/app.js
@@ -126,6 +126,15 @@ app.use(i18n.init)
// routes without sessions
// static files
app.use('/', express.static(path.join(__dirname, '/public'), { maxAge: config.staticCacheTime }))
+app.use('/docs', express.static(path.resolve(__dirname, config.docsPath), { maxAge: config.staticCacheTime }))
+app.use('/uploads', express.static(path.resolve(__dirname, config.uploadsPath), { maxAge: config.staticCacheTime }))
+app.use('/default.md', express.static(path.resolve(__dirname, config.defaultNotePath), { maxAge: config.staticCacheTime }))
+app.use('/views/index.ejs', express.static(path.resolve(__dirname, config.indexPath), { maxAge: config.staticCacheTime }))
+app.use('/views/error.ejs', express.static(path.resolve(__dirname, config.errorPath), { maxAge: config.staticCacheTime }))
+app.use('/views/slide.ejs', express.static(path.resolve(__dirname, config.slidePath), { maxAge: config.staticCacheTime }))
+app.use('/views/codimd.ejs', express.static(path.resolve(__dirname, config.codimdPath), { maxAge: config.staticCacheTime }))
+app.use('/views/pretty.ejs', express.static(path.resolve(__dirname, config.prettyPath), { maxAge: config.staticCacheTime }))
+app.use('/views/js/lib/common/constant.ejs', express.static(path.resolve(__dirname, config.constantsPath), { maxAge: config.staticCacheTime }))
// session
app.use(session({ |
Previously calling `app.js` from another directory than the base directory of CodiMD would result in an error being thrown because `lib/workers/dmpWorker.js` could not be found. This change makes the function call independent of the path CodiMD is started from. Signed-off-by: WilliButz <wbutz@cyberfnord.de>
Previously it was assumed that `config.json` would be placed in the same directory as the rest of CodiMD without any optional override. This allows to override the path to the `config.json` by setting `CMD_CONFIG_FILE` to the canonical path of the desired config file. Signed-off-by: WilliButz <wbutz@cyberfnord.de>
While paths like `tmpPath` could previously be configured, they were all interpreted relative to `appRootPath` because of `path.join`. Now the configurable paths can be canonical and therefore independent of the `appRootPath`. Signed-off-by: WilliButz <wbutz@cyberfnord.de>
Images are now properly served when `config.uploadsPath` differs from its default value. Signed-off-by: WilliButz <wbutz@cyberfnord.de>
Signed-off-by: WilliButz <wbutz@cyberfnord.de>
Signed-off-by: Claudius <opensource@amenthes.de>
d0cce34 to
d553a14
Compare
Signed-off-by: WilliButz <wbutz@cyberfnord.de>
d553a14 to
61e2401
Compare
|
@SISheogorath I updated this PR, kept the previous changes and fixed the file serving in On my test instance everything works as expected™ now :) |
|
Thanks a lot for your work 👍 Hope to see more of it in future 😉 |
Previously configurable paths like
tmpPathoruploadsPathwere interpreted as relative paths to the base directory of CodiMD. Replacingpath.joinwithpath.resolveadds the possibility of making these configurable paths canonical and therefore independent of CodiMD's base directory.A relative path in
lib/models/revision.jscaused an error to be thrown on startup when CodiMD was not startet from its base directory, this should now be fixed.I added an optional override for the path of the config file by introducing the envrionment variable
CMD_CONFIG_FILEto allowconfig.jsonto be outside of CodiMD's base directory.I also updated the README so that users are informed about both the relative paths and the optional override.