Skip to content

Commit 7359694

Browse files
committed
fix[frontend]: use full url to avoid parse error
1 parent ff5d465 commit 7359694

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

frontend/test/decrypt.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { setupServer } from "msw/node"
88
import { http, HttpResponse } from "msw"
99
import { encodeKey, encrypt, genKey } from "../utils/encryption.js"
1010
import { stubBrowerFunctions, unStubBrowerFunctions } from "./testUtils.js"
11+
import { APIUrl } from "../utils/utils.js"
1112

1213
describe("decrypt page", async () => {
1314
const scheme = "AES-GCM"
@@ -16,7 +17,7 @@ describe("decrypt page", async () => {
1617
const content = new Uint8Array(new TextEncoder().encode(contentString))
1718
const encrypted = await encrypt(scheme, key, content)
1819
const server = setupServer(
19-
http.get("/abcd", () => {
20+
http.get(`${APIUrl}/abcd`, () => {
2021
return HttpResponse.arrayBuffer(encrypted.buffer)
2122
}),
2223
)

frontend/test/index.spec.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ export const mockedPasteUpload: PasteResponse = {
1212
export const mockedPasteContent = "something"
1313

1414
export const server = setupServer(
15-
http.post("/", () => {
15+
http.post(`${APIUrl}/`, () => {
1616
return HttpResponse.json(mockedPasteUpload)
1717
}),
18-
http.get("/abcd", () => {
18+
http.get(`${APIUrl}/abcd`, () => {
1919
return HttpResponse.text(mockedPasteContent)
2020
}),
2121
)
@@ -41,6 +41,7 @@ import { PasteResponse } from "../../shared/interfaces.js"
4141
import { setupServer } from "msw/node"
4242
import { http, HttpResponse } from "msw"
4343
import { stubBrowerFunctions, unStubBrowerFunctions } from "./testUtils.js"
44+
import { APIUrl } from "../utils/utils.js"
4445

4546
describe("Pastebin", () => {
4647
it("can upload", async () => {

frontend/utils/uploader.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,13 @@ export async function uploadPaste(
6262
}
6363

6464
const contentLength = typeof options.content === "string" ? options.content.length : options.content.size
65-
const apiUrlOrManageUrl = options.isUpdate ? pasteSetting.manageUrl : APIUrl
6665

6766
try {
6867
if (contentLength < 5 * 1024 * 1024) {
69-
return await uploadNormal(apiUrlOrManageUrl, options)
68+
return await uploadNormal(APIUrl, options)
7069
} else {
7170
if (onProgress) onProgress(0)
72-
return await uploadMPU(apiUrlOrManageUrl, minChunkSize, options, (doneBytes, allBytes) => {
71+
return await uploadMPU(APIUrl, minChunkSize, options, (doneBytes, allBytes) => {
7372
if (onProgress) onProgress((100 * doneBytes) / allBytes)
7473
})
7574
}

frontend/vite.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default defineConfig(({ mode }) => {
3737
plugins: [react(), tailwindcss(), transformHtmlPlugin()],
3838
define: {
3939
DEPLOY_URL: mode === "development" ? JSON.stringify(devAPIUrl) : JSON.stringify(deployUrl),
40-
API_URL: mode === "development" ? JSON.stringify(devAPIUrl) : JSON.stringify(""),
40+
API_URL: mode === "development" ? JSON.stringify(devAPIUrl) : JSON.stringify(deployUrl),
4141
REPO: JSON.stringify(getVar("REPO")),
4242
MAX_EXPIRATION: JSON.stringify(getVar("MAX_EXPIRATION")),
4343
DEFAULT_EXPIRATION: JSON.stringify(getVar("DEFAULT_EXPIRATION")),

0 commit comments

Comments
 (0)