【问题标题】:Sails.JS partial load issue from the "assets" folder“assets”文件夹中的 Sails.JS 部分加载问题
【发布时间】:2019-01-15 10:39:31
【问题描述】:

我使用 Sails.JS 作为后端,使用 Angular 6 作为前端。在我的应用程序的 homepage.ejs 中,我需要从 assets 文件夹中加载 HTML:

<!DOCTYPE html>
 <html>

 <!-- webpack generate html -->
 <%- partial('../assets/dist/index.html') %>

</html>

但是,我在访问 http://localhost:1337/ 时遇到错误:

F:\development\SchoolERP\views\pages\homepage.ejs:5 3| 4| >> 5| 6| 7|在 Object.partial 中找不到部分 ../assets/dist/index.html (F:\development\SchoolERP\node_modules\sails\lib\hooks\views\default-view-rendering-fn.js:305:11)

然而,我的 Angular 6 URL 在http://localhost:4200 上运行良好。

【问题讨论】:

    标签: node.js angular sails.js


    【解决方案1】:

    我也遇到了这个问题,In Sails documentationsais 当你提升你的应用程序时,资产目录的内容将被移动到 .tmp/public,这意味着你构建后的 Angular 脚本将http://localhost:1337/dist/index.html 中可用,考虑到这一点,我按照以下步骤解决了这个问题:

    1. 修改homepage.ejs如下:

       // Ichange this line:
       <%- partial('../assets/dist/index.html') %>
       // for this one:
       <%- include ../../.tmp/public/dist/index.html %>
       // You just have to add the relative path for index.html
       // generated when you lift sails
      
    2. 我在 config/http.js 中取消了以下行的注释:

      order: [
       'cookieParser',
       'session',
       'bodyParser',
       'compress',
       // 'poweredBy',
       'router',
       'www',
       'favicon',
      ],    
      
    3. 告诉 angular 在哪里可以找到他的脚本,因此使用以下命令构建您的 ng-app:

      $ ng build --base-href /dist/
      
    4. 现在提升您的应用程序和角度将在http://localhost:1337/

    希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-28
      • 1970-01-01
      • 2015-07-24
      • 2011-02-21
      • 1970-01-01
      相关资源
      最近更新 更多