javascript - Node Express 未获取 bootstrap.js 文件

标签 javascript node.js mongodb express extjs

我有一个目录结构:

projectName
    | -.sencha/
    | - app/
        | - view
        | - controller
        | - store
    | - saas
    | - server/
        | -server.js
    | - index.html
    | - bootstrap.js
    | - app.js

I would like to start my app and serve index.html with node. So in server/server.js I have:

app.get('/', function(req, res) {
  res.sendFile('index.html', { root: path.join(__dirname, '../') });
})

And this is working fine but after this my localhost throwing an error bootstrap.js is not found.

index.html

    <!DOCTYPE HTML>
    <html manifest="">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta charset="UTF-8">

        <title>serverApp</title>

        <!-- The line below must be kept intact for Sencha Cmd to build your application -->
        <script id="microloader" type="text/javascript" src="bootstrap.js"></script>

    </head>
    <body></body>
    </html>

那你能告诉我如何解决这个问题吗? 或者您能给我提供一个在 extjs、express、nodejs、mongodb 中开发的示例的良好链接吗?

最佳答案

在这一点上我 100% 同意@Adam 的观点!此外,您应该将公共(public)文件夹解析为绝对路径,这不是必须的,而是指导方针,这样我们就不会受到打击...;)

您应该按照 @Adam 的建议重组您的应用程序,再加上

执行以下操作,它将通过良好的指导解决您的问题。

var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var app = express();


 app.use(bodyParser.json());
 app.use(bodyParser.urlencoded({ extended: false }));
 app.use(cookieParser());



//This will enable you to access it form '/'
app.use('/', express.static(__dirname + '/public', {index: "index.html"}));

// Rest of the stuff

然后,如果您访问您设置并移植的 URL,您就可以访问。

推荐使用 express.static 来提供静态内容。

希望对你有帮助!

关于javascript - Node Express 未获取 bootstrap.js 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35650026/

相关文章:

javascript - 使用forever运行node.js脚本

javascript - 使用 Electron-Vue.js 的串口

python - MongoEngine文档中嵌入的多个文档不一样

javascript - 是否可以结合 document.ready 功能和按钮点击功能?

javascript - 如何在移动设备上使用 jQuery onload 更改文本?

javascript - 箭头函数在 react 函数中不起作用

php - 如何为 zend 服务器(PHP)安装 MongoDb 驱动程序

javascript - 如何保存 OS X 仪表板小部件生成的文件?

javascript - 自更新至 0.10.4 以来 sails 升力错误

node.js - Node+MongoDB - 错误 : process. nextTick(function() { throw err; });