caching and redirection changes
This commit is contained in:
@@ -1,5 +1,30 @@
|
|||||||
// @refresh reload
|
// @refresh reload
|
||||||
import { injectSpeedInsights } from "@vercel/speed-insights";
|
import { injectSpeedInsights } from "@vercel/speed-insights";
|
||||||
import { mount, StartClient } from "@solidjs/start/client";
|
import { mount, StartClient } from "@solidjs/start/client";
|
||||||
|
|
||||||
|
// Handle chunk loading failures from stale cache
|
||||||
|
window.addEventListener("error", (event) => {
|
||||||
|
if (
|
||||||
|
event.message?.includes("Importing a module script failed") ||
|
||||||
|
event.message?.includes("Failed to fetch dynamically imported module")
|
||||||
|
) {
|
||||||
|
console.warn("Chunk load error detected, reloading page...");
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener("unhandledrejection", (event) => {
|
||||||
|
if (
|
||||||
|
event.reason?.message?.includes("Importing a module script failed") ||
|
||||||
|
event.reason?.message?.includes(
|
||||||
|
"Failed to fetch dynamically imported module"
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
console.warn("Chunk load error detected, reloading page...");
|
||||||
|
event.preventDefault();
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
injectSpeedInsights();
|
injectSpeedInsights();
|
||||||
mount(() => <StartClient />, document.getElementById("app")!);
|
mount(() => <StartClient />, document.getElementById("app")!);
|
||||||
|
|||||||
@@ -1,20 +1,29 @@
|
|||||||
import { Show } from "solid-js";
|
import { Show } from "solid-js";
|
||||||
import { query } from "@solidjs/router";
|
import { query, redirect } from "@solidjs/router";
|
||||||
import { Title, Meta } from "@solidjs/meta";
|
import { Title, Meta } from "@solidjs/meta";
|
||||||
import { createAsync } from "@solidjs/router";
|
import { createAsync } from "@solidjs/router";
|
||||||
import { getRequestEvent } from "solid-js/web";
|
import { getEvent } from "vinxi/http";
|
||||||
import PostForm from "~/components/blog/PostForm";
|
import PostForm from "~/components/blog/PostForm";
|
||||||
import "../post.css";
|
import "../post.css";
|
||||||
|
|
||||||
const getAuthState = query(async () => {
|
const getAuthState = query(async () => {
|
||||||
"use server";
|
"use server";
|
||||||
const { getPrivilegeLevel, getUserID } = await import("~/server/utils");
|
const { getPrivilegeLevel, getUserID } = await import("~/server/utils");
|
||||||
const event = getRequestEvent()!;
|
const event = getEvent()!;
|
||||||
const privilegeLevel = await getPrivilegeLevel(event.nativeEvent);
|
const privilegeLevel = await getPrivilegeLevel(event);
|
||||||
const userID = await getUserID(event.nativeEvent);
|
const userID = await getUserID(event);
|
||||||
|
|
||||||
|
// Return 401 for non-admin users
|
||||||
|
if (privilegeLevel !== "admin") {
|
||||||
|
throw new Response("Unauthorized", { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
return { privilegeLevel, userID };
|
return { privilegeLevel, userID };
|
||||||
}, "auth-state");
|
}, "create-post-auth");
|
||||||
|
|
||||||
|
export const route = {
|
||||||
|
load: () => getAuthState()
|
||||||
|
};
|
||||||
|
|
||||||
export default function CreatePost() {
|
export default function CreatePost() {
|
||||||
const authState = createAsync(() => getAuthState());
|
const authState = createAsync(() => getAuthState());
|
||||||
@@ -27,20 +36,8 @@ export default function CreatePost() {
|
|||||||
content="Create a new blog post with rich text editing, image uploads, and tag management."
|
content="Create a new blog post with rich text editing, image uploads, and tag management."
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Show
|
<Show when={authState()?.userID}>
|
||||||
when={authState()?.privilegeLevel === "admin"}
|
<PostForm mode="create" userID={authState()!.userID} />
|
||||||
fallback={
|
|
||||||
<div class="w-full pt-[30vh] text-center">
|
|
||||||
<div class="text-text text-2xl">Unauthorized</div>
|
|
||||||
<div class="text-subtext0 mt-4">
|
|
||||||
You must be an admin to create posts.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Show when={authState()?.userID}>
|
|
||||||
<PostForm mode="create" userID={authState()!.userID} />
|
|
||||||
</Show>
|
|
||||||
</Show>
|
</Show>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Show } from "solid-js";
|
|||||||
import { useParams, query } from "@solidjs/router";
|
import { useParams, query } from "@solidjs/router";
|
||||||
import { Title, Meta } from "@solidjs/meta";
|
import { Title, Meta } from "@solidjs/meta";
|
||||||
import { createAsync } from "@solidjs/router";
|
import { createAsync } from "@solidjs/router";
|
||||||
import { getRequestEvent } from "solid-js/web";
|
import { getEvent } from "vinxi/http";
|
||||||
import PostForm from "~/components/blog/PostForm";
|
import PostForm from "~/components/blog/PostForm";
|
||||||
import "../post.css";
|
import "../post.css";
|
||||||
|
|
||||||
@@ -10,9 +10,14 @@ const getPostForEdit = query(async (id: string) => {
|
|||||||
"use server";
|
"use server";
|
||||||
const { getPrivilegeLevel, getUserID, ConnectionFactory } =
|
const { getPrivilegeLevel, getUserID, ConnectionFactory } =
|
||||||
await import("~/server/utils");
|
await import("~/server/utils");
|
||||||
const event = getRequestEvent()!;
|
const event = getEvent()!;
|
||||||
const privilegeLevel = await getPrivilegeLevel(event.nativeEvent);
|
const privilegeLevel = await getPrivilegeLevel(event);
|
||||||
const userID = await getUserID(event.nativeEvent);
|
const userID = await getUserID(event);
|
||||||
|
|
||||||
|
// Return 401 for non-admin users
|
||||||
|
if (privilegeLevel !== "admin") {
|
||||||
|
throw new Response("Unauthorized", { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
const conn = ConnectionFactory();
|
const conn = ConnectionFactory();
|
||||||
const query = `SELECT * FROM Post WHERE id = ?`;
|
const query = `SELECT * FROM Post WHERE id = ?`;
|
||||||
@@ -33,6 +38,10 @@ const getPostForEdit = query(async (id: string) => {
|
|||||||
return { post, tags, privilegeLevel, userID };
|
return { post, tags, privilegeLevel, userID };
|
||||||
}, "post-for-edit");
|
}, "post-for-edit");
|
||||||
|
|
||||||
|
export const route = {
|
||||||
|
load: ({ params }: { params: { id: string } }) => getPostForEdit(params.id)
|
||||||
|
};
|
||||||
|
|
||||||
export default function EditPost() {
|
export default function EditPost() {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const data = createAsync(() => getPostForEdit(params.id));
|
const data = createAsync(() => getPostForEdit(params.id));
|
||||||
@@ -64,31 +73,19 @@ export default function EditPost() {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Show
|
<Show
|
||||||
when={data()?.privilegeLevel === "admin"}
|
when={data() && postData()}
|
||||||
fallback={
|
fallback={
|
||||||
<div class="w-full pt-[30vh] text-center">
|
<div class="w-full pt-[30vh] text-center">
|
||||||
<div class="text-text text-2xl">Unauthorized</div>
|
<div class="text-text text-xl">Loading post...</div>
|
||||||
<div class="text-subtext0 mt-4">
|
|
||||||
You must be an admin to edit posts.
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Show
|
<PostForm
|
||||||
when={data() && postData()}
|
mode="edit"
|
||||||
fallback={
|
postId={parseInt(params.id)}
|
||||||
<div class="w-full pt-[30vh] text-center">
|
initialData={postData()!}
|
||||||
<div class="text-text text-xl">Loading post...</div>
|
userID={data()!.userID}
|
||||||
</div>
|
/>
|
||||||
}
|
|
||||||
>
|
|
||||||
<PostForm
|
|
||||||
mode="edit"
|
|
||||||
postId={parseInt(params.id)}
|
|
||||||
initialData={postData()!}
|
|
||||||
userID={data()!.userID}
|
|
||||||
/>
|
|
||||||
</Show>
|
|
||||||
</Show>
|
</Show>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
22
vercel.json
Normal file
22
vercel.json
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"headers": [
|
||||||
|
{
|
||||||
|
"source": "/(.*)",
|
||||||
|
"headers": [
|
||||||
|
{
|
||||||
|
"key": "Cache-Control",
|
||||||
|
"value": "public, max-age=0, stale-while-revalidate=60"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"source": "/_build/(.*)",
|
||||||
|
"headers": [
|
||||||
|
{
|
||||||
|
"key": "Cache-Control",
|
||||||
|
"value": "public, max-age=31536000, immutable"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user