0

For some reason if i specify port to listen in server.js, for example 4242, but not process.env.PORT, my .css files stop working (with process.env.PORT it's working).

Code example:
Server.js:

var express = require('express');
var app = express()
  , http = require('http')
  , server = http.createServer(app)

app.get('/room', function (req, res) {
    res.render('room.ejs')   
});

server.listen(4242);

room.ejs:

<head>
    <link rel="stylesheet" type="text/css" href="style.css" />
    <meta charset="utf-8" />
    <title></title>
</head>
///rest of HTML///

style.css file itself is in public folder that is in site's folder.

4

1 回答 1

1

尝试告诉 express 位于的静态文件夹在哪里server.js

app.use(express.static(__dirname + '/public'));

并改变:

<link rel="stylesheet" type="text/css" href="/style.css" />  //see the / on css route
于 2013-06-01T16:36:35.480 回答