Skip to content

Commit

Permalink
fix: Sitemap resource loading issue (#4042)
Browse files Browse the repository at this point in the history
## Description

1. What is this PR about (link the issue and add a short description)

## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
5de6)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env` file
  • Loading branch information
istarkov committed Aug 31, 2024
1 parent e77528b commit f25ca10
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions apps/builder/app/shared/$resources/sitemap.xml.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { json } from "@remix-run/server-runtime";
import { prisma } from "@webstudio-is/prisma-client";
import { parsePages } from "@webstudio-is/project-build/index.server";
import { getStaticSiteMapXml } from "@webstudio-is/sdk";
import { parseBuilderUrl } from "../router-utils/origins";
import { isBuilder } from "../router-utils";

/**
* This should be a route in SvelteKit, as it can be fetched server-side without an actual HTTP request.
Expand All @@ -10,24 +12,16 @@ import { getStaticSiteMapXml } from "@webstudio-is/sdk";
* Note: We are not moving this to routes to avoid generating an additional 30MB function on deploy.
*/
export const loader = async ({ request }: { request: Request }) => {
const referer = request.headers.get("referer");

if (referer == null) {
throw json({ message: "No referer" }, { status: 400 });
if (isBuilder(request) === false) {
throw new Error("Only builder requests are allowed");
}

const segments = new URL(referer).pathname.slice(1).split("/");

if (segments.length !== 2) {
throw json({ message: "Invalid referer" }, { status: 400 });
}
const { projectId } = parseBuilderUrl(request.url);

if (segments[0] !== "builder") {
throw json({ message: "Invalid referer" }, { status: 400 });
if (projectId === undefined) {
throw new Error("projectId is required");
}

const projectId = segments[1];

// get pages from the database
const build = await prisma.build.findFirst({
where: {
Expand Down

0 comments on commit f25ca10

Please sign in to comment.