-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
51 lines (45 loc) · 1.21 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// server.js
const jsonServer = require('json-server');
const server = jsonServer.create();
const middlewares = jsonServer.defaults();
const router = jsonServer.router('db.json');
server.use(middlewares);
server.use(jsonServer.bodyParser);
// Middleware d'authentification
server.post('/auth/login', (req, res) => {
const { email, password } = req.body;
// Simuler une vérification
if (email === "[email protected]" && password === "password123") {
res.json({
success: true,
token: "mock_jwt_token_123",
user: {
id: 1,
email: email,
name: "Test User"
}
});
} else {
res.status(401).json({
success: false,
message: "Invalid credentials"
});
}
});
server.post('/auth/register', (req, res) => {
const { email, password, name } = req.body;
// Simuler un enregistrement
res.json({
success: true,
token: "mock_jwt_token_456",
user: {
id: Date.now(),
email,
name
}
});
});
server.use(router);
server.listen(3001, () => {
console.log('JSON Server is running on port 3001');
});