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

Add task management data and enable CORS in server #10

Open
wants to merge 1 commit into
base: api
Choose a base branch
from
Open
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
33 changes: 33 additions & 0 deletions server/data/tasks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { v4 as uuidv4 } from 'uuid';

export const allTasks = new Map();

allTasks
.set(uuidv4(), {
title: 'Re-work UI/UX',
priority: 'Low',
releaseDate: '12/05/2025',
assignedTo: 'Said, Rachael, Alejandro',
projectName: 'Time App',
})
.set(uuidv4(), {
title: 'Dark mode toggle',
priority: 'High',
releaseDate: '09/03/2025',
assignedTo: 'Umair, Precious',
projectName: 'ASA Darkmode Feature',
})
.set(uuidv4(), {
title: 'Accessibility checks',
priority: 'Medium',
releaseDate: '15/04/2025',
assignedTo: 'Michael, Ricardo',
projectName: 'Time App',
})
.set(uuidv4(), {
title: 'Notification integration',
priority: 'High',
releaseDate: '11/03/2025',
assignedTo: 'Ebtesam, Deborah',
projectName: 'Time App',
});
23 changes: 23 additions & 0 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"license": "ISC",
"description": "",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.21.2",
"nodemon": "^3.1.9",
"uuid": "^11.1.0"
Expand Down
6 changes: 4 additions & 2 deletions server/server.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const express = require('express');
import express from 'express'
const app = express();
import cors from 'cors';
import {allTasks} from './data/tasks.js';
const port = process.env.PORT || 3333;

// ...existing code...
app.use(express.json());
app.use(cors());

app.get('/tasks', (req, res) => {
res.json(allTasks);
res.json(Array.from(allTasks.values()));
});

app.post('/tasks', (req, res) => {
Expand Down
2 changes: 1 addition & 1 deletion web/src/hooks/useFetchData.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const useFetchData = (endpoint) => {
const fetchData = async () => {
setIsLoading(true);
try {
const response = await fetch(`/api/${endpoint}`);
const response = await fetch(`http://localhost:3333/${endpoint}`);
if (!response.ok) {
throw new Error('Something went wrong!');
}
Expand Down
15 changes: 0 additions & 15 deletions web/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,7 @@ import { DataFetchingDemoPage } from './pages/DataFetchingDemoPage.jsx';
import { TaskLayout } from './pages/TaskLayout/TaskLayout.jsx';
import { TaskForm } from './components/domains/task/TaskForm/TaskForm';

async function enableMocking() {
if (import.meta.env === 'development') {
return;
}

const { worker } = await import('./mocks/browser');

// `worker.start()` returns a Promise that resolves
// once the Service Worker is up and ready to intercept requests.
return worker.start({
onUnhandledRequest: 'bypass', // Allows non-mocked requests to pass through
});
}

enableMocking().then(() => {
createRoot(document.getElementById('root')).render(
<StrictMode>
<BrowserRouter>
Expand All @@ -43,4 +29,3 @@ enableMocking().then(() => {
</BrowserRouter>
</StrictMode>,
);
});