Просмотр исходного кода

Merge pull request #558 from porter-dev/master

Merge cache-control fix to staging
abelanger5 5 лет назад
Родитель
Сommit
ef8e8486d0

+ 1 - 0
.github/workflows/dev.yaml

@@ -31,6 +31,7 @@ jobs:
           FEEDBACK_ENDPOINT=${{secrets.FEEDBACK_ENDPOINT}}
           POSTHOG_API_KEY=${{secrets.POSTHOG_API_KEY}}
           POSTHOG_HOST=${{secrets.POSTHOG_HOST}}
+          SEGMENT_PUBLIC_KEY=${{secrets.SEGMENT_PUBLIC_KEY}}
           APPLICATION_CHART_REPO_URL=${{secrets.APPLICATION_CHART_REPO_URL}}
           EOL
       - name: Build

+ 3 - 10
dashboard/src/main/home/cluster-dashboard/expanded-chart/status/Logs.tsx

@@ -64,7 +64,6 @@ export default class Logs extends Component<PropsType, StateType> {
       return <Log key={i}>
         {this.state.logs[i].map((ansi, j) => {
           if (ansi.clearLine) {
-            console.log("CLEAR LINE IS", ansi.clearLine)
             return null
           }
 
@@ -85,9 +84,7 @@ export default class Logs extends Component<PropsType, StateType> {
       `${protocol}://${process.env.API_SERVER}/api/projects/${currentProject.id}/k8s/${selectedPod?.metadata?.namespace}/pod/${selectedPod?.metadata?.name}/logs?cluster_id=${currentCluster.id}&service_account_id=${currentCluster.service_account_id}`
     );
 
-    this.ws.onopen = () => {
-      console.log("connected to websocket");
-    };
+    this.ws.onopen = () => {};
 
     this.ws.onmessage = (evt: MessageEvent) => {
       let ansiLog = Anser.ansiToJson(evt.data)
@@ -102,13 +99,9 @@ export default class Logs extends Component<PropsType, StateType> {
       });
     };
 
-    this.ws.onerror = (err: ErrorEvent) => {
-      console.log("websocket error:", err);
-    };
+    this.ws.onerror = (err: ErrorEvent) => {};
 
-    this.ws.onclose = () => {
-      console.log("closing pod logs");
-    };
+    this.ws.onclose = () => {};
   };
 
   refreshLogs = () => {

+ 10 - 0
server/router/router.go

@@ -3,6 +3,8 @@ package router
 import (
 	"net/http"
 	"os"
+	"path"
+	"strings"
 
 	"github.com/go-chi/chi"
 	"github.com/porter-dev/porter/internal/auth/token"
@@ -1358,8 +1360,16 @@ func New(a *api.App) *chi.Mux {
 
 	r.Get("/*", func(w http.ResponseWriter, r *http.Request) {
 		if _, err := os.Stat(staticFilePath + r.RequestURI); os.IsNotExist(err) {
+			w.Header().Set("Cache-Control", "no-cache")
+
 			http.StripPrefix(r.URL.Path, fs).ServeHTTP(w, r)
 		} else {
+			// Set static files involving html, js, or empty cache to "no-cache", which means they must be validated
+			// for changes before the browser uses the cache
+			if base := path.Base(r.URL.Path); strings.Contains(base, "html") || strings.Contains(base, "js") || base == "." || base == "/" {
+				w.Header().Set("Cache-Control", "no-cache")
+			}
+
 			fs.ServeHTTP(w, r)
 		}
 	})