-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Allow custom robots text pages #1104
Conversation
pkg/app/pagewriter/static_pages.go
Outdated
_, err := rw.Write(content) | ||
if err != nil { | ||
logger.Printf("Error writing %q: %v", pageName, err) | ||
s.errorPageWriter.WriteErrorPage(rw, http.StatusInternalServerError, "", err.Error()) |
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 will need a req *http.Request
after my RequestID PR to extract out the {{.RequestID}} from the request.
pkg/app/pagewriter/static_pages.go
Outdated
// Statis files include: | ||
// - robots.txt | ||
func loadStaticPages(customDir string) (map[string][]byte, error) { | ||
pages := make(map[string][]byte) |
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.
For how this is passed around and manipulated by reference in all these functions, does this make sense as a type
(or full struct) with these all as member methods manipulating it?
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.
maybe a struct it looks like with the pages & customDir as member fields?
Expect(err).ToNot(HaveOccurred()) | ||
|
||
robotsTxtFile := filepath.Join(customDir, robotsTxtName) | ||
Expect(ioutil.WriteFile(robotsTxtFile, []byte(customRobots), 0600)).To(Succeed()) |
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.
Expect(ioutil.WriteFile(robotsTxtFile, []byte(customRobots), 0600)).To(Succeed()) | |
Expect(ioutil.WriteFile(robotsTxtFile, []byte(customRobots), 0400)).To(Succeed()) |
|
||
var _ = Describe("Static Pages", func() { | ||
var customDir string | ||
const customRobots = "I AM A ROBOT!!!" |
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.
NIT: Can we have this custom test payload resemble the robots.txt traditional structure?
@NickMeves please take a look now it has been updated, created a separate pageGetter struct, not sure whether it makes it simpler or not, WDYT? |
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.
LGTM!
I agree on the code complexity/size even with the struct route. But at least its a little bit easier to eyeball/follow than a complex map passed around to be manipulated -- thanks for making the shift!
Added changelog entry, not other changes since last review |
Description
This allows users to replace our static robots.txt content by using the templates dir option and placing a robots text inside the directory.
Motivation and Context
Users should be able to customise this content.
Fixes #1068
This also sets the stage for serving other static files.
At the moment, we embed CSS and other files in our pages, maybe we went to serve that as static files too?
How Has This Been Tested?
Unit testing only.
Checklist: