Express virtual path prefix not working with angular 6 app












0















I'm hosting my angular 6 app with express static



app.use(express.static('/', __dirname +'/client/angular'));


The problem came when i tried to add another page to my server as a landing page. So i specified a mounth path '/app' to my angular app.



app.use(express.static('/app', __dirname +'/client/angular'));


This is not working! When i run the server this came out




GET /app/ 304 4.294 ms - -



GET /inline.bundle.js/ 404 1.065 ms - 15



GET /polyfills.bundle.js/ 404 0.581 ms - 15



GET /styles.bundle.js/ 404 2.195 ms - 15



GET /vendor.bundle.js/ 404 2.119 ms - 15



GET /main.bundle.js/ 404 1.830 ms - 15



GET /favicon.ico 404 0.474 ms - 15




I managed the problem hosting the new webpage in a virtual path '/home' and keep my angular app hosted in the root path by default.



app.use('/home', express.static(__dirname +'/client/landing'));
app.use('/', express.static(__dirname +'/client/angular'));


But these are not the routes i need so, does anybody know how to mount an angular app on express virtual path?










share|improve this question



























    0















    I'm hosting my angular 6 app with express static



    app.use(express.static('/', __dirname +'/client/angular'));


    The problem came when i tried to add another page to my server as a landing page. So i specified a mounth path '/app' to my angular app.



    app.use(express.static('/app', __dirname +'/client/angular'));


    This is not working! When i run the server this came out




    GET /app/ 304 4.294 ms - -



    GET /inline.bundle.js/ 404 1.065 ms - 15



    GET /polyfills.bundle.js/ 404 0.581 ms - 15



    GET /styles.bundle.js/ 404 2.195 ms - 15



    GET /vendor.bundle.js/ 404 2.119 ms - 15



    GET /main.bundle.js/ 404 1.830 ms - 15



    GET /favicon.ico 404 0.474 ms - 15




    I managed the problem hosting the new webpage in a virtual path '/home' and keep my angular app hosted in the root path by default.



    app.use('/home', express.static(__dirname +'/client/landing'));
    app.use('/', express.static(__dirname +'/client/angular'));


    But these are not the routes i need so, does anybody know how to mount an angular app on express virtual path?










    share|improve this question

























      0












      0








      0








      I'm hosting my angular 6 app with express static



      app.use(express.static('/', __dirname +'/client/angular'));


      The problem came when i tried to add another page to my server as a landing page. So i specified a mounth path '/app' to my angular app.



      app.use(express.static('/app', __dirname +'/client/angular'));


      This is not working! When i run the server this came out




      GET /app/ 304 4.294 ms - -



      GET /inline.bundle.js/ 404 1.065 ms - 15



      GET /polyfills.bundle.js/ 404 0.581 ms - 15



      GET /styles.bundle.js/ 404 2.195 ms - 15



      GET /vendor.bundle.js/ 404 2.119 ms - 15



      GET /main.bundle.js/ 404 1.830 ms - 15



      GET /favicon.ico 404 0.474 ms - 15




      I managed the problem hosting the new webpage in a virtual path '/home' and keep my angular app hosted in the root path by default.



      app.use('/home', express.static(__dirname +'/client/landing'));
      app.use('/', express.static(__dirname +'/client/angular'));


      But these are not the routes i need so, does anybody know how to mount an angular app on express virtual path?










      share|improve this question














      I'm hosting my angular 6 app with express static



      app.use(express.static('/', __dirname +'/client/angular'));


      The problem came when i tried to add another page to my server as a landing page. So i specified a mounth path '/app' to my angular app.



      app.use(express.static('/app', __dirname +'/client/angular'));


      This is not working! When i run the server this came out




      GET /app/ 304 4.294 ms - -



      GET /inline.bundle.js/ 404 1.065 ms - 15



      GET /polyfills.bundle.js/ 404 0.581 ms - 15



      GET /styles.bundle.js/ 404 2.195 ms - 15



      GET /vendor.bundle.js/ 404 2.119 ms - 15



      GET /main.bundle.js/ 404 1.830 ms - 15



      GET /favicon.ico 404 0.474 ms - 15




      I managed the problem hosting the new webpage in a virtual path '/home' and keep my angular app hosted in the root path by default.



      app.use('/home', express.static(__dirname +'/client/landing'));
      app.use('/', express.static(__dirname +'/client/angular'));


      But these are not the routes i need so, does anybody know how to mount an angular app on express virtual path?







      node.js express angular6 static-files virtual-path






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 3:08









      Felipe ToledoFelipe Toledo

      5619




      5619
























          1 Answer
          1






          active

          oldest

          votes


















          0














          After digging a little bit more, i found out that I have to modify the index.html file of my angular app in the dist folder generated after run ng build. The problem was that the base href was "/", so when it needed the js files it didn't find them. So, all we have to do is change it, with the same path as it was mounted in the server



            <base href="/app">





          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440208%2fexpress-virtual-path-prefix-not-working-with-angular-6-app%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            After digging a little bit more, i found out that I have to modify the index.html file of my angular app in the dist folder generated after run ng build. The problem was that the base href was "/", so when it needed the js files it didn't find them. So, all we have to do is change it, with the same path as it was mounted in the server



              <base href="/app">





            share|improve this answer






























              0














              After digging a little bit more, i found out that I have to modify the index.html file of my angular app in the dist folder generated after run ng build. The problem was that the base href was "/", so when it needed the js files it didn't find them. So, all we have to do is change it, with the same path as it was mounted in the server



                <base href="/app">





              share|improve this answer




























                0












                0








                0







                After digging a little bit more, i found out that I have to modify the index.html file of my angular app in the dist folder generated after run ng build. The problem was that the base href was "/", so when it needed the js files it didn't find them. So, all we have to do is change it, with the same path as it was mounted in the server



                  <base href="/app">





                share|improve this answer















                After digging a little bit more, i found out that I have to modify the index.html file of my angular app in the dist folder generated after run ng build. The problem was that the base href was "/", so when it needed the js files it didn't find them. So, all we have to do is change it, with the same path as it was mounted in the server



                  <base href="/app">






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 16 hours ago

























                answered Dec 2 '18 at 22:12









                Felipe ToledoFelipe Toledo

                5619




                5619
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440208%2fexpress-virtual-path-prefix-not-working-with-angular-6-app%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Xamarin.form Move up view when keyboard appear

                    Post-Redirect-Get with Spring WebFlux and Thymeleaf

                    Anylogic : not able to use stopDelay()