-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
37 lines (31 loc) · 788 Bytes
/
main.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
// Node.js Core Modules
const http = require('http');
// App Routes
const homeRoutes = require('./home/routes');
const blogRoutes = require('./blog/routes');
const coursesRoutes = require('./courses/routes');
// Utils
const { flatRoutes } = require('./utils/flatRoutes');
// Routing
const routes = {
'': homeRoutes,
'/blog': blogRoutes,
'/courses': coursesRoutes,
};
const realRoutes = flatRoutes(routes);
console.log(realRoutes);
function router(req, res) {
console.log(req.url);
const actualRoute = realRoutes[req.url];
if (!actualRoute) {
console.log('404');
res.write('404');
} else {
console.log('Routing:');
actualRoute(req, res);
}
res.end();
}
// Run server
http.createServer(router).listen(3000);
console.log('Escuchando el puerto 3000');