
Agregar recursos a mi index con fs
Publicado por Juan (1 intervención) el 21/09/2017 18:15:28
Hola espero me puedan ayudar estoy creando un server con node en el cual tengo mi index pero necesito que me jale los recursos tales como css y js pero no puedo hacer la lectura de ellos
app.js
index.html
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var app = require('http').createServer(handler);
var io = require('socket.io').listen(app);
var fs = require('fs');
var mySocket = 0;
app.listen(3000);
function handler(req, res) {
if (req.url.indexOf('/') != -1) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('error load index');
}
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
res.end();
});
}
}}
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<html>
<head>
<title>Notificación</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="/socket.io/socket.io.js"></script>
</head>
<body>
</body>
</html>
Valora esta pregunta


0