【发布时间】:2019-03-28 17:04:34
【问题描述】:
我尝试运行我的网站 2 方法。
1) 通过使用节点
2)不使用节点(只是我的电脑上的index.html)
但是,就链接样式表而言,结果是不同的。没有节点,样式标签中的样式表可以像往常一样链接。但是,当使用节点作为服务器时,样式表无法链接。
这是我的代码结构。
/app
/server.js
/views
/statics
/index.html
/partials
/public
/javascript
/css
/main.css
/images
这里是 index.html 头标签
<link rel="stylesheet" type="text/css" media="screen" href="../../public/css/main.css">
server.js
const express = require('express')
const app = express()
const path = require('path')
// no need to use app.use(app.router) because of that update
// function signature express.static(root, [options])
app.use(express.static('public'));
// mount root to views/statics
app.use('/', express.static('views/statics'));
const PORT = process.env.PORT || 3000;
app.listen(PORT,() => {
console.log(`Server is listening on port ${PORT}`)
});
【问题讨论】: