SailsJs - 从资产中提供Angular App

时间:2021-01-20 20:41:37

Within a new SailsJs application I'm trying to serve an angular app from the assets folder. Considering assets/admin/index.html I can access localhost:1337/admin, however, none of the additional js files or sub-directories can be accessed. I've even checked the .tmp/public folder and everything is copying over correctly but when I try to refer to any file within the admin folder other than index.html it can not be found.

在一个新的SailsJs应用程序中,我正在尝试从assets文件夹中提供角度应用程序。考虑到assets / admin / index.html我可以访问localhost:1337 / admin,但是,没有其他js文件或子目录可以访问。我甚至检查了.tmp / public文件夹,所有内容都正确复制,但是当我尝试引用除index.html之外的admin文件夹中的任何文件时,都找不到它。

SailsJs  - 从资产中提供Angular App

Referring to angular module in index.html

参考index.html中的角度模块

<!--Sailes IO Library-->
<script src="/js/dependencies/sails.io.js"></script>

<!--Vendor Scripts-->
<script src="/js/angular-animate.js"></script>
<script src="/js/angular-aria.js"></script>
<script src="/js/angular-material.js"></script>
<script src="/js/angular-messages.js"></script>
<script src="/js/angular.js"></script>
<script src="/js/release/angular-ui-router.js"></script>

<!--Admin Application Definition-->
<script src="/admin/app.js"></script>
<script src="/admin/config/router.js"></script>

However, app.js is not being served!

但是,没有提供app.js!

SailsJs  - 从资产中提供Angular App

Can I not do it this way? How can I access my angular application files from the admin folder?

我不能这样做吗?如何从admin文件夹访问我的角度应用程序文件?

2 个解决方案

#1


1  

To load an angular application in sails.js you need to serve the index.html file from the views folder.

要在sails.js中加载角度应用程序,您需要从views文件夹中提供index.html文件。

so in you config/routes.js

所以你在config / routes.js

'/': {
    view: 'homepage'
}

this means when you hit the root of you application then homepage.ejs from the views folder is served

这意味着当您点击应用程序的根目录时,将提供views文件夹中的homepage.ejs

copy the contents of assest/admin/index.html file in homepage.ejs and if necessary check that all the link and script tags have the file path relative to assets folder.

复制homepage.ejs中assest / admin / index.html文件的内容,并在必要时检查所有链接和脚本标记是否具有相对于assets文件夹的文件路径。

once the homepage is served you can use angular ui router for routing purpose

一旦主页服务,您可以使用角度ui路由器进行路由

Note--

change your localhost:1337/admin to

将您的localhost:1337 / admin更改为

localhost:1337

#2


0  

After reading the documentation a little more in-depth, sails will also serve index.html files found in the assets folder. So I created a new folder, inside that folder I created a new index.html and app.js file, and then lifted. My index.html file was then available at a url that matched my folder name. My folder was called "admin" so navigating to localhost:1337/admin loaded my index.html page.

在更深入地阅读文档后,sails还将提供assets文件夹中的index.html文件。所以我创建了一个新文件夹,在该文件夹中我创建了一个新的index.html和app.js文件,然后解除了。然后,我的index.html文件在与我的文件夹名称匹配的网址上可用。我的文件夹名为“admin”,因此导航到localhost:1337 / admin加载了我的index.html页面。

As far as serving the other dependencies, I used grunt-bower and a new grunt task to start serving my bower_components over to my assets/vendor folder.

至于服务其他依赖项,我使用grunt-bower和一个新的grunt任务开始将我的bower_components提供给我的assets / vendor文件夹。

#1


1  

To load an angular application in sails.js you need to serve the index.html file from the views folder.

要在sails.js中加载角度应用程序,您需要从views文件夹中提供index.html文件。

so in you config/routes.js

所以你在config / routes.js

'/': {
    view: 'homepage'
}

this means when you hit the root of you application then homepage.ejs from the views folder is served

这意味着当您点击应用程序的根目录时,将提供views文件夹中的homepage.ejs

copy the contents of assest/admin/index.html file in homepage.ejs and if necessary check that all the link and script tags have the file path relative to assets folder.

复制homepage.ejs中assest / admin / index.html文件的内容,并在必要时检查所有链接和脚本标记是否具有相对于assets文件夹的文件路径。

once the homepage is served you can use angular ui router for routing purpose

一旦主页服务,您可以使用角度ui路由器进行路由

Note--

change your localhost:1337/admin to

将您的localhost:1337 / admin更改为

localhost:1337

#2


0  

After reading the documentation a little more in-depth, sails will also serve index.html files found in the assets folder. So I created a new folder, inside that folder I created a new index.html and app.js file, and then lifted. My index.html file was then available at a url that matched my folder name. My folder was called "admin" so navigating to localhost:1337/admin loaded my index.html page.

在更深入地阅读文档后,sails还将提供assets文件夹中的index.html文件。所以我创建了一个新文件夹,在该文件夹中我创建了一个新的index.html和app.js文件,然后解除了。然后,我的index.html文件在与我的文件夹名称匹配的网址上可用。我的文件夹名为“admin”,因此导航到localhost:1337 / admin加载了我的index.html页面。

As far as serving the other dependencies, I used grunt-bower and a new grunt task to start serving my bower_components over to my assets/vendor folder.

至于服务其他依赖项,我使用grunt-bower和一个新的grunt任务开始将我的bower_components提供给我的assets / vendor文件夹。