我在 Node js 上使用 Dyson 模块,但我的应用找不到 css 文件夹。 我有这个:
/demoDyson
dyson-demo.js
/node_modules
/public
/css
style.css
/services
/GET
_index.js
test.js
dyson-demo.js:
var express = require('express'),
dyson = require('dyson'),
path = require('path');
dyson.bootstrap({
configDir: __dirname + '/services',
port: 8765
});
var myApp = express();
myApp.use(express.static(path.join(__dirname, 'public')));
_index.js:
module.exports = {
path: '/',
render: function(req, res) {
var html = '<h1>dyson</h1><p>Example endpoints:</p>';
var examples = [
'/test'
];
html += '<ul>' + examples.map(function(example) {
return '<li><a href="' + example + '">' + example + '</a></li>';
}).join('') + '</ul>';
res.send(200, html);
}
};
测试.js :
var path = require('path');
module.exports = {
path: '/test',
render: function (req, res) {
res.sendFile(path.resolve(__dirname + '/../../public/index.html'));
}
};
现在,要加载 public 文件夹中的 index.html 文件,浏览器控制台会提示找不到 css。 有什么想法吗?
最佳答案
当您运行 dyson API 时,它不会与 express 中间件结合使用。我建议您做的是,只需使用 './' + pathToTheFile
或者您可以在线上传带有 .css
扩展名的 css 文件,然后将其链接到您的 html .
关于javascript - CSS 未找到戴森模块 Node ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45955986/