Skip to content

Commit

Permalink
Merge pull request #37 from FokkoVeegens/20-solve-cors-issue-for-visu…
Browse files Browse the repository at this point in the history
…al-studio-feeds

Solve CORS issues for Visual Studio feeds
  • Loading branch information
FokkoVeegens authored Jan 9, 2025
2 parents 5de052d + f5eb3de commit 65993e1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
8 changes: 7 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
"run",
"dev"
],
"port": 3000, // Default port for Vite development server
"console": "integratedTerminal",
"env": {
"NO_COLOR": "1"
},
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bhttp://localhost:([0-9]+)\\b",
}
}
]
}
14 changes: 7 additions & 7 deletions src/pages/Index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const Index = () => {
}, []);

useEffect(() => {
const fetchRSSItems = async () => {;

const fetchRSSItems = async () => {
const proxyUrl = 'https://corsproxy.io/?url=';
const counts = {};
let totalItems = 0;
const uniqueItems = new Map();
Expand All @@ -36,8 +36,7 @@ const Index = () => {
try {
let response;
if (feed.cors) {
// Todo: Use a proxy to avoid CORS issues
continue;
response = await fetch(proxyUrl + encodeURIComponent(feed.url)).then(res => res.text());
} else {
response = await fetch(feed.url).then(res => res.text());
}
Expand Down Expand Up @@ -67,7 +66,9 @@ const Index = () => {
}
}

uniqueItems.forEach((value, title) => {
const sortedItems = Array.from(uniqueItems.entries()).sort((a, b) => new Date(b[1].pubDate) - new Date(a[1].pubDate));

sortedItems.forEach(([title, value]) => {
const newsItem = document.createElement('div');
newsItem.className = 'news-item';
newsItem.innerHTML = `
Expand Down Expand Up @@ -148,8 +149,7 @@ const Index = () => {
<div id="filter-buttons">
<button className="filter-btn" onClick={unselectFiltersAndShowAll}>All ({totalItemCount})</button>
{
feeds.filter(feed => !feed.cors)
.map(feed => (
feeds.map(feed => (
<button
key={feed.name}
className="filter-btn"
Expand Down
2 changes: 2 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ a {
}

.news-item {
flex: 1 1 100%; /* Adjust the width as needed */
box-sizing: border-box; /* Ensure padding and border are included in the width */
max-width: 600px;
margin: 10px;
padding: 15px;
Expand Down
1 change: 1 addition & 0 deletions vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default defineConfig({
base: basename,
build: {
outDir: 'dist',
sourcemap: true,
},
publicDir: 'public',
define: {
Expand Down

0 comments on commit 65993e1

Please sign in to comment.