简体   繁体   中英

CSS is not loading in easyrtc application on node.js

I've some css issues in my easyrtc application, Here is my physical file structure

  • project

    • login
      • css
        • style.css
      • js
        • script.css
      • login.html
      • logout.html
    • node_modules
    • static
      • server.js
      • package.json

In the server.js I've defined,

app.get('/', function(req, res, next) {
 res.redirect('/login');
});

and

app.get('/login', function(req, res, next) {
 res.sendfile('login.html', {root: './login'});
});

In my login.html I've include following link

<link rel="stylesheet" href="css/login.css" media="screen" type="text/css" />

Also I've tried with

<link rel="stylesheet" href="./login/css/login.css" media="screen" type="text/css" />

But this css file is not loading to browser, I've inspect the element. But there was an empty css file in sources. How can I fix this? What is the root of localhost:8080 my webserver running in port 8080 Although I go through the this nodejs express solution but I'm afraid can use this kind of solution for my existing project. If yes how can I add express middle-ware to load css? Help in advance. May the FOSS be with you.

The usual server.js used with easyrtc (as supplied in the server_example directory) has a directory called static that serves as the root directory of the static files getting served. For example, if you put files called xxx.html and yyy.css in the static folder, you could reference xxx as

  http://yoursite.com/xxx.html 

and inside xxx.html you could reference yyy.css in your link statements as

href="yyy.css"

or

href="/yyy.css"

Needless to say, subdirectories work as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM