D
D
Dvorak2016-05-28 14:55:39
Node.js
Dvorak, 2016-05-28 14:55:39

Why is it not possible to give css files?

var types = {
  '.js': 'text/javascript',
  '.css': 'text/css',
  '.html': 'text.html',
  '.jpg': 'image/jpg'
};

http.createServer(function(req, res) {
  fs.readFile('index.html', 'utf-8', function(err, data) {
    if (err) {
      console.log(err);
    } else {
      var pathname = path.extname(req.url);
      res.writeHead(200, {'Content-type': types[pathname]});
      console.log(pathname);
      res.end(data);
    }

  })




}).listen(8080);

There is the following code, nothing complicated. html - files are displayed normally, but css-styles are not loaded. What could be wrong?
Z.Y. All relevant modules connected

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2016-05-28
@allishappy

If I see correctly, you are only reading index.html and only giving it back, only with different content-types.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question