-
-
Notifications
You must be signed in to change notification settings - Fork 377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed build for usage without subdomain #806
Conversation
|
||
if [ -n "${SITE_ID}" ]; then | ||
#replace "site_id: 'remark'" by SITE_ID | ||
se -i "s|'remark'|'${SITE_ID}'|g" /srv/web/*.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think SITE_ID
could be passed via env vars on build time without replacing it after.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if I will build my own docker image this pull request not needed. But I use public docker imageumputun/remark42
and this changes will fix it for usage without subdomain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replacing remark
could cause side-effects like replacing this word in unexpected palaces.
I could suggest putting unique value or template like expression to places that we want to replace.
Something like {% SITE_ID %}
and comment about how it works.
The same we should do for replacing REMARK_URL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, current solution is dirty hack. And site_id
is hard coded. But this script called only inside docker container. Would not this solution break the usage without docker on bare metal?
If I will add expressions like {% SITE_ID %}
and {% REMARK_URL %}
it will keep the same after npm run build
. And replace expressions to correct values will require postbuild
script with sed
commands.
I don't know how to fix this correctly, given what I said above.
Or am I wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, you are right. And now we have the issue in bin build. With this PR we will fix the issue only for docker.
Let's use your fix and I will think about how to fix it in all ways for all builds.
confused. How this even related to subdomain configuration vs without subdomain configuration? Either way REMARK_URL has to be passed in or UI it won't be able to communicate with the server.
I don't get it. @akellbl4 correct if I wrong, but I think |
@umputun, I forgot to say that I made review only from code point of view. And I want to reproduce this bug and check how this PR will fix it. |
This fix affects the pages of widgets, when directly accessing them.
var remark_config = {
site_id: 'remark',
host: window.location.origin,
components: ['last-comments'] // or other
}; And this config is used to append widget scripts: (function(c) {
for (var i = 0; i < c.length; i++) {
var d = document,
s = d.createElement('script');
s.src = remark_config.host + '/web/' + c[i] + '.js';
(d.head || d.body).appendChild(s);
}
})(remark_config.components || ['embed']);
Current behavior for REMARK_URL=https://remark.example.com:
Current behavior for REMARK_URL=https://example.com/remark:
My patches force to set correct REMARK_URL and SITE_ID to relevant variables: var remark_config = {
site_id: 'mysiteid',
host: 'https://example.com/remark' || window.location.origin,
components: ['last-comments'] // or other
}; And |
thx for the detailed explanation. sed we currently doing is not something I proud of. If possible it will be nice to resolve the issue without adding more seds. |
|
And if create serving templates instead static files it will be step to solve style customization issue #5 |
@sattellite as I said in comments all of these things could be done only with passing env vars via webpack to templates and js. UPD: I've checked our building process again. And if we want to handle it via webpack we need to do it on the build stage and variables pass to container on run time. It means we could change these vars only by sed or be serving them and replace it by go. |
This bug relative to the PR. |
Agree with you. Serving with go web-server also can help solve other problems, as I said upper. Does this mean that I need to add patches to process this with go? |
@umputun wdyt? Using I prefer to stay with |
yeah, agree. will keep sed for now |
frontend/webpack.config.js
Outdated
@@ -180,21 +180,33 @@ module.exports = () => ({ | |||
new Html({ | |||
template: path.resolve(__dirname, 'index.ejs'), | |||
inject: false, | |||
templateParameters: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for mixing you up. This way is absolutely useless for us and we can remove these params.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This option allows use REMARK_URL
instead of htmlWebpackPlugin.options.REMARK_URL
https://github.com/jantimon/html-webpack-plugin#:~:text=templateParameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I understand. But it's useless because we should to replace strings only on running time with passed vars to env and this template compilation will be done on building stage.
frontend/last-comments.ejs
Outdated
@@ -25,7 +25,7 @@ | |||
<script> | |||
var remark_config = { | |||
site_id: 'remark', | |||
host: window.location.origin, | |||
host: '<%= REMARK_URL %>' || window.location.origin, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
REMARK_URL
is required param. It means this expression will always return the first value and we don't need to keep window.location.origin
REMARK_URL is required and window.location.origin is not needed. umputun#806 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx
REMARK_URL is required and window.location.origin is not needed. #806 (comment)
I installed remark42 in the easiest way from the docker. Configured nginx to use app without subdomain. It works okay for comments but widgets not working as expected. Widgets use it own config with host as window.location.origin which returns the fqdn only.
This can be fixed on server side by multiple sed commands in container like this
docker exec -it remark42 sed -i "s|host: window.location.origin|host: 'https://b.sattellite.me/comments/'|g" /srv/web/last-comments.html
I prepared fix to code for exclude this problem in future:
site_id
by 'remark' to environment SITE_ID.