-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
25 lines (22 loc) · 784 Bytes
/
Copy pathapp.js
File metadata and controls
25 lines (22 loc) · 784 Bytes
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
import http from 'node:http';
import url from 'node:url';
import { registerUser, loginUser, getUserProfile } from './controllers/userController.js';
const server = http.createServer((req, res) => {
const parseUrl = url.parse(req.url, true);
const path = parseUrl.pathname
const method = req.method
if(path === '/register' && method === 'POST') {
registerUser(req, res)
} else if (path === '/login' && method === 'POST') {
loginUser(req, res)
} else if (path === '/profile' && method === 'GET') {
getUserProfile(req, res)
} else {
res.writeHead(404, { 'Content-type' : 'application/json'})
res.end(JSON.stringify({ message: 'Route not found'}))
}
})
const PORT = 3334
server.listen(PORT, () => {
console.log(`Server running on port ${PORT}`)
})