javascript - CSS 未找到戴森模块 Node

标签 javascript html node.js node-modules

我在 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/

相关文章:

node.js - Dockerizing 一个 React App : The app starts inside the container, 但它不能从暴露的端口访问

node.js - 如何将 npm 链接与只能通过 ssh 访问的 git 存储库一起使用

c# - 如何使用 json.stringify 将对象列表从 View 传递到 MVC Controller

javascript - 无法添加属性 "X",对象不可扩展 Angular 9

php - 如何检查访问者从哪个链接被重定向

javascript - 提交表单后获取复选框值

javascript - 为 iPad 设置不同的初始缩放级别

javascript - 将 html 内容包装在一个 div 中

javascript - 如何在没有任何库的情况下使用 HTML、CSS、JavaScript 中的 json 数据绘制图形

javascript - 它们如何代表电影在 imdb、烂番茄上的平均评分?