我使用Node.js在Linux机器上托管服务器,目前这是文件结构:
网络服务器
->node_modules (express, mysql2, path - only using express so far)
->client
-->index.hmtl
-->style
--->style.css
-->js
--->index.js
->server
-->server.js
的index.html:
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Pootid</title>
<link href=style/index.css rel=stylesheet>
<script src=js/test.js></script>
</head>
<body>
<header>
</header>
<article>
<p>Hi this is a webpage</p>
<p>Hi this is another paragraph</p>
</article>
<footer>
</footer>
</body>
index.css:
body {
background: red;
}
index.js:
'use strict'
window.addEventListener("load", boot);
async function boot() {
test();
}
function test() {
console.log("this is a test");
}
server.js:
'use strict'
const express = require('express');
const app = express();
const path = require('path');
app.listen(8080);
//app.listen(80);
app.get('/api/test', test);
app.use('/', express.static('webpages'));
app.get('/*', (req, res) => {
const top = path.resolve('.');
const dir = `${top}/client/index.html`;
res.sendFile(path.join(dir));
});
function test(req, res) {
const testObject = {
"test": "this is a test"
};
res.json(testObject);
}
浏览器中的当前css文件:
这似乎只是html的副本,我不认为这与网络设置有关。