Skip to content

Commit ed182ee

Browse files
authored
Merge pull request #9 from e-conomic/msc/add-mock-server
Add basic http mock server
2 parents 62f3963 + 29c0744 commit ed182ee

6 files changed

Lines changed: 69 additions & 10 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ Don’t worry about authentication — you can assume your application is alread
5252

5353
Prerequisites:
5454

55-
- Node v22.15 installed.
55+
- Node v24 or newer installed.
5656

5757
Steps to run locally:
5858

59-
- Clone the project.
60-
- run `npm install`
61-
- run `npm run dev`
59+
1. Clone the project.
60+
2. Run `npm install`.
61+
3. Run `npm run dev` — this starts the Vite dev server and the mock API
6262

6363
Happy coding!

package-lock.json

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"private": true,
44
"version": "0.0.0",
55
"type": "module",
6+
"engines": {
7+
"node": ">=24.0.0"
8+
},
69
"scripts": {
710
"dev": "vite",
811
"build": "tsc -b && vite build",
@@ -17,6 +20,7 @@
1720
},
1821
"devDependencies": {
1922
"@eslint/js": "^9.25.0",
23+
"@types/node": "^24.10.0",
2024
"@types/react": "^19.1.2",
2125
"@types/react-dom": "^19.1.2",
2226
"@vitejs/plugin-react": "^4.4.1",

src/api/projects.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
const BASE_URL = "https://localhost:7029/api"
2-
31
export async function getAllProjects() {
4-
const response = await fetch(`${BASE_URL}/projects/get-all`);
5-
return response.json();
2+
const response = await fetch('/api/projects/get-all')
3+
return response.json()
64
}

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"files": [],
33
"references": [
44
{ "path": "./tsconfig.app.json" },
5-
{ "path": "./tsconfig.node.json" }
5+
{ "path": "./tsconfig.node.json" },
6+
{ "path":"./tsconfig.server.json" }
67
]
78
}

vite.config.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
1+
import type { Plugin } from 'vite'
12
import { defineConfig } from 'vite'
23
import tailwindcss from '@tailwindcss/vite'
34
import react from '@vitejs/plugin-react'
45

6+
const MOCK_PROJECTS = [
7+
{ id: '1', name: 'Alpha Project', createdOn: '2024-01-15T10:00:00Z', updatedOn: '2025-02-20T14:30:00Z' },
8+
{ id: '2', name: 'Beta Initiative', createdOn: '2024-03-01T09:00:00Z', updatedOn: '2025-02-18T11:00:00Z' },
9+
{ id: '3', name: 'Gamma Dashboard', createdOn: '2024-06-10T08:00:00Z', updatedOn: '2025-02-25T09:15:00Z' },
10+
]
11+
12+
function mockApiPlugin(): Plugin {
13+
return {
14+
name: 'mock-api',
15+
configureServer(server) {
16+
server.middlewares.use((req, res, next) => {
17+
if (req.url === '/api/projects/get-all' && req.method === 'GET') {
18+
res.setHeader('Content-Type', 'application/json')
19+
res.end(JSON.stringify(MOCK_PROJECTS))
20+
return
21+
}
22+
next()
23+
})
24+
},
25+
}
26+
}
27+
528
// https://vite.dev/config/
629
export default defineConfig({
7-
plugins: [react(), tailwindcss()],
30+
plugins: [react(), tailwindcss(), mockApiPlugin()],
831
})

0 commit comments

Comments
 (0)