-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd737f0
commit c8d943a
Showing
8 changed files
with
94 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
version: v1 | ||
renderingConfig: | ||
pageWaitTime: 5 | ||
pageWaitTime: 10 | ||
pageWaitCondition: '(function() { return window.prerenderReady === true })()' | ||
requestHeaders: | ||
- name: "X-Grender-Request" | ||
value: "1" | ||
# requestHeaders: | ||
# - name: "X-Grender-Request" | ||
# value: "1" | ||
server: | ||
port: "8080" | ||
headers: | ||
port: "8081" | ||
responseHeaders: | ||
- name: "X-Prerender" | ||
value: "1" | ||
backend: | ||
fileSystem: | ||
baseDir: "./tmp" | ||
# fileSystem: | ||
# baseDir: "./tmp" | ||
s3: | ||
bucketName: "grender.io" | ||
region: "ap-southeast-2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package pilot | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/krishanthisera/grender/backend" | ||
) | ||
|
||
// Rendering handler | ||
func (C *Config) renderHandler(ctx *gin.Context) { | ||
url := ctx.Param("url") | ||
fmt.Println(url) | ||
|
||
var be backend.Backend | ||
var err error | ||
|
||
// Check S3 backend configuration | ||
if s3 := C.Backend.S3; s3.BucketName != "" { | ||
be, err = createBackendFromConfig(s3) | ||
} else if fs := C.Backend.FileSystem; fs.BaseDir != "" { | ||
// Check FileSystem backend configuration | ||
be, err = createBackendFromConfig(fs) | ||
} else { | ||
// No backend found | ||
fmt.Println("No backend found") | ||
} | ||
|
||
if err != nil { | ||
fmt.Println(err) | ||
ctx.String(http.StatusInternalServerError, "Error creating backend: %v", err) | ||
return | ||
} | ||
rac := renderAndCacheConfig{backend: &be, render: &C.RenderingConfig} | ||
renderedHTML, err := rac.RenderAndCache(url) | ||
|
||
// Page is rendered successfully | ||
if renderedHTML != nil { | ||
// Setting required headers | ||
C.addResponseHeaders(ctx) | ||
ctx.Data(http.StatusOK, "text/html", []byte(renderedHTML)) | ||
|
||
// Page cannot be cached | ||
if err != nil { | ||
ctx.String(http.StatusInternalServerError, "Error caching URL: %v", err) | ||
return | ||
} | ||
return | ||
} | ||
|
||
// Page cannot be rendered | ||
ctx.String(http.StatusInternalServerError, "Error rendering URL: %v", err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters