remark42 icon indicating copy to clipboard operation
remark42 copied to clipboard

Right way to pass SITE_ID and REMARK_URL to templates

Open akellbl4 opened this issue 4 years ago • 4 comments

Now we build frontend and then on the running stage replace these constants with sed. It works only for docker image. We don't do it for binary packages (correct me if I'm wrong). I will check how it works in it.

I think we should discuss and find out the right way to do it for any kind of build. We found out another one way to do it with serving templates on Go and insert them. This way also has another advantage: we can rid off the request to get config and pass it in the template right on sending HTML to a client.

cc @umputun @paskal

Related: #567 #806

akellbl4 avatar Nov 10 '20 11:11 akellbl4

HTML generation is a messy task no matter where you do it, and usually, I would vote against coupling frontend and backend in such a strong way. But, as we have such a small amount of the HTML I think it's not that bad, and I would indeed be glad to get rid of sed. I think we should go for it. @umputun?

paskal avatar Nov 29 '20 23:11 paskal

I don't think such a coupling worths it as seds replacement. However processing html/js on the server side (like applying templates and setting extra headers) has many other good uses. For example, support of styles upload via server API and applying styles on the fly. Another example - setting some headers, like frame-ancestors, dynamically.

So, as much as I don't like the potential coupling, in our case it may have some valuable benefits.

umputun avatar Jan 20 '21 05:01 umputun

@akellbl4 I see that now we have some hardcoded variables next to the htmlWebpackPlugin.options. Can we reuse the same mechanism for SITE_ID for consistency?

    site_id: 'remark',
    host: '<%= htmlWebpackPlugin.options.REMARK_URL %>',

paskal avatar Jan 08 '23 15:01 paskal

cc @sattellite as he seems to be the person who added it in the first place.

paskal avatar Jan 08 '23 15:01 paskal