You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by "jamesfredley (via GitHub)" <gi...@apache.org> on 2025/10/01 14:00:56 UTC
[PR] Add HtaccessTask to generate .htaccess for dist output [grails-static-website]
jamesfredley opened a new pull request, #389:
URL: https://github.com/apache/grails-static-website/pull/389
Introduces a new Gradle task, HtaccessTask, to generate a .htaccess file in the dist folder for Apache web server configuration. The task is registered in GrailsWebsitePlugin and is finalized by the main buildWebsite task to ensure the .htaccess file is created as part of the website build process.
CSP permissions approved on: https://issues.apache.org/jira/browse/INFRA-27297?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add HtaccessTask to generate .htaccess, CSP allow kapa.ai bot [grails-static-website]
Posted by "jamesfredley (via GitHub)" <gi...@apache.org>.
jamesfredley commented on PR #389:
URL: https://github.com/apache/grails-static-website/pull/389#issuecomment-3361370627
We will have a Kapa.ai demo widget to test next week and this will be required when we actually go live, in addition to adding some JS to the website and docs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add HtaccessTask to generate .htaccess, CSP allow kapa.ai bot [grails-static-website]
Posted by "jamesfredley (via GitHub)" <gi...@apache.org>.
jamesfredley commented on code in PR #389:
URL: https://github.com/apache/grails-static-website/pull/389#discussion_r2423204179
##########
buildSrc/src/main/groovy/org/grails/gradle/HtaccessTask.groovy:
##########
Review Comment:
url was a leftover and unused, so removing it was correct.
The `\n`'s and `+`'s gave me a bit of PTSD, but I like the idea of having each entry listed on its own line.
I took all of these changes and tweaked `HT_ACCESS_CONTENT` as follows.
```
private static final List<String> DOMAINS = [
'https://*.kapa.ai/',
'https://kapa-widget-proxy-la7dkmplpq-uc.a.run.app',
'https://www.google.com/recaptcha/',
'https://www.gstatic.com/recaptcha/',
'https://hcaptcha.com',
'https://*.hcaptcha.com'
]
private static String HT_ACCESS_CONTENT =
'# CSP permissions for grails.apache.org - https://issues.apache.org/jira/browse/INFRA-27297\n' +
'# Ref https://docs.kapa.ai/integrations/understanding-csp-cors\n' +
'SetEnv CSP_PROJECT_DOMAINS "' + DOMAINS.join(' ') + '"'
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add HtaccessTask to generate .htaccess, CSP allow kapa.ai bot [grails-static-website]
Posted by "matrei (via GitHub)" <gi...@apache.org>.
matrei commented on code in PR #389:
URL: https://github.com/apache/grails-static-website/pull/389#discussion_r2399812795
##########
buildSrc/src/main/groovy/org/grails/gradle/GrailsWebsitePlugin.groovy:
##########
@@ -43,6 +43,7 @@ class GrailsWebsitePlugin implements Plugin<Project> {
public static final String GROUP_GRAILS = 'grails'
public static final String TASK_RENDER_BLOG = 'renderBlog'
public static final String TASK_RENDER_MINUTES = 'renderMinutes'
+ public static final String TASK_GEN_HTACCESS = "genHtaccess"
Review Comment:
Align on single quotes for strings?
##########
buildSrc/src/main/groovy/org/grails/gradle/GrailsWebsitePlugin.groovy:
##########
@@ -180,6 +181,17 @@ class GrailsWebsitePlugin implements Plugin<Project> {
task.setGroup(GROUP_GRAILS)
})
+ project.tasks.register(TASK_GEN_HTACCESS, HtaccessTask, { task ->
+ Object extension = project.getExtensions().findByName(EXTENSION_NAME)
+ if (extension instanceof SiteExtension) {
+ SiteExtension siteExtension = ((SiteExtension) extension)
+ task.setProperty("output", siteExtension.output)
+ task.setProperty("url", siteExtension.url)
+ }
+ task.setDescription('Generates .htaccess file in the dist folder for Apache web server configuration')
+ task.setGroup(GROUP_GRAILS)
+ })
Review Comment:
```suggestion
project.tasks.register(TASK_GEN_HTACCESS, HtaccessTask) { task ->
project.extensions.findByType(SiteExtension).with {
task.output.set(output)
}
task.description = 'Generates .htaccess file in the dist folder for Apache web server configuration'
task.group = GROUP_GRAILS
}
```
##########
buildSrc/src/main/groovy/org/grails/gradle/HtaccessTask.groovy:
##########
Review Comment:
Suggestion for readability and simplification:
```groovy
package org.grails.gradle
import groovy.transform.CompileStatic
import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
@CompileStatic
class HtaccessTask extends DefaultTask {
private static String HT_ACCESS_CONTENT =
'# CSP permissions for grails.apache.org - https://issues.apache.org/jira/browse/INFRA-27297\n' +
'# Ref https://docs.kapa.ai/integrations/understanding-csp-cors\n' +
'SetEnv CSP_PROJECT_DOMAINS "' +
'https://*.kapa.ai/ ' +
'https://kapa-widget-proxy-la7dkmplpq-uc.a.run.app ' +
'https://www.google.com/recaptcha/ ' +
'https://www.gstatic.com/recaptcha/ ' +
'https://hcaptcha.com ' +
'https://*.hcaptcha.com' +
'"'
@Input
final Property<File> output = project.objects.property(File)
@OutputFile
final RegularFileProperty htaccessFile = project.objects.fileProperty()
HtaccessTask() {
htaccessFile.convention(
project.layout.buildDirectory.file('dist/.htaccess')
)
}
@TaskAction
void generateHtaccess() {
def outputDir = new File(output.get(), 'dist').tap {
mkdirs()
}
def htaccess = new File(outputDir, '.htaccess').tap {
text = HT_ACCESS_CONTENT
}
logger.lifecycle("Generated .htaccess file at: $htaccess.absolutePath")
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add HtaccessTask to generate .htaccess, CSP allow kapa.ai bot [grails-static-website]
Posted by "jamesfredley (via GitHub)" <gi...@apache.org>.
jamesfredley commented on code in PR #389:
URL: https://github.com/apache/grails-static-website/pull/389#discussion_r2423198486
##########
buildSrc/src/main/groovy/org/grails/gradle/GrailsWebsitePlugin.groovy:
##########
@@ -43,6 +43,7 @@ class GrailsWebsitePlugin implements Plugin<Project> {
public static final String GROUP_GRAILS = 'grails'
public static final String TASK_RENDER_BLOG = 'renderBlog'
public static final String TASK_RENDER_MINUTES = 'renderMinutes'
+ public static final String TASK_GEN_HTACCESS = "genHtaccess"
Review Comment:
Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add HtaccessTask to generate .htaccess, CSP allow kapa.ai bot [grails-static-website]
Posted by "jamesfredley (via GitHub)" <gi...@apache.org>.
jamesfredley merged PR #389:
URL: https://github.com/apache/grails-static-website/pull/389
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org