Code for my personal website
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: handle origin url

+28 -8
+1 -1
astro.config.mjs
··· 40 40 adapter: node({ 41 41 mode: 'standalone' 42 42 }) 43 - }); 43 + });
+14 -4
src/lib/kommentar.ts
··· 7 7 }; 8 8 9 9 type PostComment = ({ 10 + baseUrl, 10 11 comment, 11 12 sessionId 12 13 }: { 14 + baseUrl: string; 13 15 comment: CommentToPost; 14 16 sessionId: string; 15 17 }) => Promise<Comment>; 16 18 type GetComments = ({ 19 + baseUrl, 17 20 hostId 18 21 }: { 22 + baseUrl: string; 19 23 hostId: Comment['hostId']; 20 24 }) => Promise<Comment[] | []>; 21 25 type MapComment = (comment: Comment) => Comment; 26 + 27 + const removeTrailingSlash = (url: string) => { 28 + return url.endsWith('/') ? url.slice(0, -1) : url; 29 + }; 22 30 23 31 const mapComment: MapComment = (comment) => { 24 32 const mapped = { ··· 42 50 return mapped; 43 51 }; 44 52 45 - const postComment: PostComment = async ({ comment, sessionId }) => { 53 + const postComment: PostComment = async ({ baseUrl, comment, sessionId }) => { 54 + const base = removeTrailingSlash(baseUrl); 46 55 const response = await fetch( 47 - `http://localhost:3000/api/kommentar/comments/${comment.hostId}`, 56 + `${base}/api/kommentar/comments/${comment.hostId}`, 48 57 { 49 58 method: 'POST', 50 59 headers: { ··· 60 69 return postedComment; 61 70 }; 62 71 63 - const getComments: GetComments = async ({ hostId }) => { 64 - const fetchUrl = `http://localhost:3000/api/kommentar/comments/${hostId}`; 72 + const getComments: GetComments = async ({ baseUrl, hostId }) => { 73 + const base = removeTrailingSlash(baseUrl); 74 + const fetchUrl = `${base}/api/kommentar/comments/${hostId}`; 65 75 66 76 const response = await fetch(fetchUrl, { 67 77 method: 'GET',
+5 -1
src/pages/blog/[...slug].astro
··· 89 89 90 90 if (!hasErrors && Astro.cookies.has('userSessionId')) { 91 91 await postComment({ 92 + baseUrl: String(Astro.url.origin), 92 93 comment: { 93 94 hostId: String(`blog-${slug}`), 94 95 content: String(comment.trim()), ··· 113 114 } 114 115 } 115 116 116 - const comments = await getComments({ hostId: `blog-${slug}` }); 117 + const comments = await getComments({ 118 + baseUrl: String(Astro.url.origin), 119 + hostId: `blog-${slug}` 120 + }); 117 121 --- 118 122 119 123 <Layout title={String(blogPost.title)} description={String(blogPost.excerpt)}>
+5 -1
src/pages/projects/[...slug].astro
··· 92 92 93 93 if (!hasErrors && Astro.cookies.has('userSessionId')) { 94 94 await postComment({ 95 + baseUrl: String(Astro.url.origin), 95 96 comment: { 96 97 hostId: String(`projects-${slug}`), 97 98 content: String(comment.trim()), ··· 116 117 } 117 118 } 118 119 119 - const comments = await getComments({ hostId: `projects-${slug}` }); 120 + const comments = await getComments({ 121 + baseUrl: String(Astro.url.origin), 122 + hostId: `projects-${slug}` 123 + }); 120 124 --- 121 125 122 126 <Layout
+3 -1
tsconfig.json
··· 5 5 "outDir": "./dist", 6 6 "paths": { 7 7 "@/*": ["*"] 8 - } 8 + }, 9 + "sourceMap": true, 10 + "inlineSourceMap": false 9 11 } 10 12 }