Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve CORS issues for Visual Studio feeds #37

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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=';
FokkoVeegens marked this conversation as resolved.
Show resolved Hide resolved
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