Next.js under a proxy with different path2019 Community Moderator ElectionDifference between proxy server and reverse proxy serverGetting git to work with a proxy serverHow do I get the path to the current script with Node.js?Proxy server with Node.js on HerokuWhat's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?What's the difference between tilde(~) and caret(^) in package.json?proxy won't work in create-react-app and axiosExpress & http-proxy-middleware for images proxyWhen I change url in a middleware, it does not jump to next middleware even that middleware match pattern pathCan't pass req.params when using http-proxy-middleware … NodeJS/Express

Should we avoid writing fiction about historical events without extensive research?

What is "desert glass" and what does it do to the PCs?

I can't die. Who am I?

Paper published similar to PhD thesis

How can friction do no work in case of pure rolling?

Are there other characters in the Star Wars universe who had damaged bodies and needed to wear an outfit like Darth Vader?

Drawing the Möbius band and the Klein bottle

Preparing as much as possible of a cake in advance

Calculate total length of edges in select Voronoi diagram

Are Wave equations equivalent to Maxwell equations in free space?

If nine coins are tossed, what is the probability that the number of heads is even?

Can a Mexican citizen living in US under DACA drive to Canada?

School performs periodic password audits. Is my password compromised?

Linear Combination of Atomic Orbitals

PTiJ: How should animals pray?

3.5% Interest Student Loan or use all of my savings on Tuition?

Is being socially reclusive okay for a graduate student?

Affine transformation of circular arc in 3D

Align equations with text before one of them

Dukha vs legitimate need

Split a number into equal parts given the number of parts

Ultrafilters as a double dual

Is this nominative case or accusative case?

Problems with rounding giving too many digits



Next.js under a proxy with different path



2019 Community Moderator ElectionDifference between proxy server and reverse proxy serverGetting git to work with a proxy serverHow do I get the path to the current script with Node.js?Proxy server with Node.js on HerokuWhat's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?What's the difference between tilde(~) and caret(^) in package.json?proxy won't work in create-react-app and axiosExpress & http-proxy-middleware for images proxyWhen I change url in a middleware, it does not jump to next middleware even that middleware match pattern pathCan't pass req.params when using http-proxy-middleware … NodeJS/Express










2















Using next.js version 8.0.3 I don't know how to serve a custom server under a proxy with a different subpath.



I'm doing:



npm run build && npm start



In order to build and open the custom server.



And instead of open http://localhost:3000, I'm using a proxy with another subpath http://localhost:8000/example.



The proxy is simple, to reproduce it:



proxy.js



const express = require('express')
const proxy = require('http-proxy-middleware')

const options =
target:'http://localhost:3000/',

const exampleProxy = proxy(options)
const app = express()

app.use('/example', exampleProxy)
app.listen(8000)


And then:



node proxy.js


However, when I open the http://localhost:8000/example url is loading the home page but without styles, statics, javascript... Anything...



How can I do it correctly?



Thank you so much!










share|improve this question


























    2















    Using next.js version 8.0.3 I don't know how to serve a custom server under a proxy with a different subpath.



    I'm doing:



    npm run build && npm start



    In order to build and open the custom server.



    And instead of open http://localhost:3000, I'm using a proxy with another subpath http://localhost:8000/example.



    The proxy is simple, to reproduce it:



    proxy.js



    const express = require('express')
    const proxy = require('http-proxy-middleware')

    const options =
    target:'http://localhost:3000/',

    const exampleProxy = proxy(options)
    const app = express()

    app.use('/example', exampleProxy)
    app.listen(8000)


    And then:



    node proxy.js


    However, when I open the http://localhost:8000/example url is loading the home page but without styles, statics, javascript... Anything...



    How can I do it correctly?



    Thank you so much!










    share|improve this question
























      2












      2








      2








      Using next.js version 8.0.3 I don't know how to serve a custom server under a proxy with a different subpath.



      I'm doing:



      npm run build && npm start



      In order to build and open the custom server.



      And instead of open http://localhost:3000, I'm using a proxy with another subpath http://localhost:8000/example.



      The proxy is simple, to reproduce it:



      proxy.js



      const express = require('express')
      const proxy = require('http-proxy-middleware')

      const options =
      target:'http://localhost:3000/',

      const exampleProxy = proxy(options)
      const app = express()

      app.use('/example', exampleProxy)
      app.listen(8000)


      And then:



      node proxy.js


      However, when I open the http://localhost:8000/example url is loading the home page but without styles, statics, javascript... Anything...



      How can I do it correctly?



      Thank you so much!










      share|improve this question














      Using next.js version 8.0.3 I don't know how to serve a custom server under a proxy with a different subpath.



      I'm doing:



      npm run build && npm start



      In order to build and open the custom server.



      And instead of open http://localhost:3000, I'm using a proxy with another subpath http://localhost:8000/example.



      The proxy is simple, to reproduce it:



      proxy.js



      const express = require('express')
      const proxy = require('http-proxy-middleware')

      const options =
      target:'http://localhost:3000/',

      const exampleProxy = proxy(options)
      const app = express()

      app.use('/example', exampleProxy)
      app.listen(8000)


      And then:



      node proxy.js


      However, when I open the http://localhost:8000/example url is loading the home page but without styles, statics, javascript... Anything...



      How can I do it correctly?



      Thank you so much!







      node.js proxy next.js






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      Aral RocaAral Roca

      1,80622446




      1,80622446






















          1 Answer
          1






          active

          oldest

          votes


















          1














          As a caveat, I'll start by saying that I don't believe NextJS plays nice with proxies, especially on a subpath.



          That being said, the following should work, with limitations :



          const express = require('express')
          const proxy = require('http-proxy-middleware')

          const options =
          target:'http://localhost:3000/',
          pathRewrite:
          '^/example': ''


          const exampleProxy = proxy(options)
          const app = express()

          app.use(['/example', '/_next', '/static'], exampleProxy)
          app.listen(8000)


          The pathRewrite option makes sure /example/xyz on the proxy redirects to /xyz on your NextJS server.



          You need to proxy /_next (or whatever you renamed your build directory to) so that your page finds all the built assets (scripts, stylesheets, webpack chunks, etc.). If you inspect any of your Next's project pages you'll see that these assets links are absolute, hence the need to proxy that directory as well.



          You need to proxy /static for the same reason, except that directory is meant to hold your static NextJS assets (images, etc.).



          You'll also notice your page links in Next are usually absolute as well (I know mine are in all my projects).



          All the above is the reason why I stated that, in my opinion, NextJS isn't really suited for a subpath proxy usage.



          Update:



          You can add the following config in your next.config.js file at the root of your NextJS project:



          module.exports = 
          assetPrefix: '/example'



          This will prepend /example to all the built assets, so instead of /_next/pages/xyz you will link to /example/_next/pages/xyz. With this update you can remove the /_next proxy on the proxy side and your buildable assets (scripts, stylesheets, etc.) should still load.



          Regarding the navigational (i.e. 'page') links within your NextJS app, as stated in my comment, you could setup your own version of Link and prepend your subpath:



          import Link from 'next/link'

          // for proxied server
          const PROXY_PATH= '/example'
          // for non-proxied server
          // const PROXY_PATH= ''

          export default MyLink = ( as, children, ...props ) => <Link ...props as=`$PROXY_PATH$as`>children</Link>


          You'd have to make sure all your MyLink components define an as prop. You don't want to change the href prop itself (the link as it is), only the as prop (the link as it appears).



          Finally, for the /static assets, you'd just have to rewrite your static links inside your NextJS app, i.e. turn



          <img src='/static/mylogo.svg' />


          to



          <img src=`$PROXY_PATH/static/mylogo.svg` />


          And the path rewrite on the proxy end should handle it correctly.
          With this, you could define PROXY_PATH at the project scope in a separate config file or load it from an environment variable.






          share|improve this answer

























          • Thank you so much to answer it! However, I guess that it is not the solution that I'm looking for :( ... Basically for two reasons: (1) The idea of the proxy is to have different projects running on different subpaths, and we can have conflicts routing paths like /static... (2) Your solution works fine to load the page with static files, however, navigating with next.js is starting from / and not from /example. I would like a solution touching only the next.js part, and not the proxy part. Is it not possible? :O Anyway thank you so much! I appreciate a lot your effort.

            – Aral Roca
            yesterday






          • 1





            @AralRoca I totally understand. As I said in my opening comment, I don't think NextJS plays nicely with a subpath proxy. There is however one thing you could do, and that would be to create your own MyLink component (inherited from Next's Link) and prepend your subpath to all links. But you'll still have to deal with the /static and build directories...

            – Jaxx
            16 hours ago











          • @AralRoca I've updated my answer with an additional configuration on the NextJS end, which would help with the build directory and the page links, but the /static assets directory remains an issue. Perhaps it could be handled with a custom server route on the NextJS side?

            – Jaxx
            15 hours ago











          • @AralRoca see my latest update for a possible (and simple) solution to the /static assets directory

            – Jaxx
            14 hours ago










          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%2f55022306%2fnext-js-under-a-proxy-with-different-path%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









          1














          As a caveat, I'll start by saying that I don't believe NextJS plays nice with proxies, especially on a subpath.



          That being said, the following should work, with limitations :



          const express = require('express')
          const proxy = require('http-proxy-middleware')

          const options =
          target:'http://localhost:3000/',
          pathRewrite:
          '^/example': ''


          const exampleProxy = proxy(options)
          const app = express()

          app.use(['/example', '/_next', '/static'], exampleProxy)
          app.listen(8000)


          The pathRewrite option makes sure /example/xyz on the proxy redirects to /xyz on your NextJS server.



          You need to proxy /_next (or whatever you renamed your build directory to) so that your page finds all the built assets (scripts, stylesheets, webpack chunks, etc.). If you inspect any of your Next's project pages you'll see that these assets links are absolute, hence the need to proxy that directory as well.



          You need to proxy /static for the same reason, except that directory is meant to hold your static NextJS assets (images, etc.).



          You'll also notice your page links in Next are usually absolute as well (I know mine are in all my projects).



          All the above is the reason why I stated that, in my opinion, NextJS isn't really suited for a subpath proxy usage.



          Update:



          You can add the following config in your next.config.js file at the root of your NextJS project:



          module.exports = 
          assetPrefix: '/example'



          This will prepend /example to all the built assets, so instead of /_next/pages/xyz you will link to /example/_next/pages/xyz. With this update you can remove the /_next proxy on the proxy side and your buildable assets (scripts, stylesheets, etc.) should still load.



          Regarding the navigational (i.e. 'page') links within your NextJS app, as stated in my comment, you could setup your own version of Link and prepend your subpath:



          import Link from 'next/link'

          // for proxied server
          const PROXY_PATH= '/example'
          // for non-proxied server
          // const PROXY_PATH= ''

          export default MyLink = ( as, children, ...props ) => <Link ...props as=`$PROXY_PATH$as`>children</Link>


          You'd have to make sure all your MyLink components define an as prop. You don't want to change the href prop itself (the link as it is), only the as prop (the link as it appears).



          Finally, for the /static assets, you'd just have to rewrite your static links inside your NextJS app, i.e. turn



          <img src='/static/mylogo.svg' />


          to



          <img src=`$PROXY_PATH/static/mylogo.svg` />


          And the path rewrite on the proxy end should handle it correctly.
          With this, you could define PROXY_PATH at the project scope in a separate config file or load it from an environment variable.






          share|improve this answer

























          • Thank you so much to answer it! However, I guess that it is not the solution that I'm looking for :( ... Basically for two reasons: (1) The idea of the proxy is to have different projects running on different subpaths, and we can have conflicts routing paths like /static... (2) Your solution works fine to load the page with static files, however, navigating with next.js is starting from / and not from /example. I would like a solution touching only the next.js part, and not the proxy part. Is it not possible? :O Anyway thank you so much! I appreciate a lot your effort.

            – Aral Roca
            yesterday






          • 1





            @AralRoca I totally understand. As I said in my opening comment, I don't think NextJS plays nicely with a subpath proxy. There is however one thing you could do, and that would be to create your own MyLink component (inherited from Next's Link) and prepend your subpath to all links. But you'll still have to deal with the /static and build directories...

            – Jaxx
            16 hours ago











          • @AralRoca I've updated my answer with an additional configuration on the NextJS end, which would help with the build directory and the page links, but the /static assets directory remains an issue. Perhaps it could be handled with a custom server route on the NextJS side?

            – Jaxx
            15 hours ago











          • @AralRoca see my latest update for a possible (and simple) solution to the /static assets directory

            – Jaxx
            14 hours ago















          1














          As a caveat, I'll start by saying that I don't believe NextJS plays nice with proxies, especially on a subpath.



          That being said, the following should work, with limitations :



          const express = require('express')
          const proxy = require('http-proxy-middleware')

          const options =
          target:'http://localhost:3000/',
          pathRewrite:
          '^/example': ''


          const exampleProxy = proxy(options)
          const app = express()

          app.use(['/example', '/_next', '/static'], exampleProxy)
          app.listen(8000)


          The pathRewrite option makes sure /example/xyz on the proxy redirects to /xyz on your NextJS server.



          You need to proxy /_next (or whatever you renamed your build directory to) so that your page finds all the built assets (scripts, stylesheets, webpack chunks, etc.). If you inspect any of your Next's project pages you'll see that these assets links are absolute, hence the need to proxy that directory as well.



          You need to proxy /static for the same reason, except that directory is meant to hold your static NextJS assets (images, etc.).



          You'll also notice your page links in Next are usually absolute as well (I know mine are in all my projects).



          All the above is the reason why I stated that, in my opinion, NextJS isn't really suited for a subpath proxy usage.



          Update:



          You can add the following config in your next.config.js file at the root of your NextJS project:



          module.exports = 
          assetPrefix: '/example'



          This will prepend /example to all the built assets, so instead of /_next/pages/xyz you will link to /example/_next/pages/xyz. With this update you can remove the /_next proxy on the proxy side and your buildable assets (scripts, stylesheets, etc.) should still load.



          Regarding the navigational (i.e. 'page') links within your NextJS app, as stated in my comment, you could setup your own version of Link and prepend your subpath:



          import Link from 'next/link'

          // for proxied server
          const PROXY_PATH= '/example'
          // for non-proxied server
          // const PROXY_PATH= ''

          export default MyLink = ( as, children, ...props ) => <Link ...props as=`$PROXY_PATH$as`>children</Link>


          You'd have to make sure all your MyLink components define an as prop. You don't want to change the href prop itself (the link as it is), only the as prop (the link as it appears).



          Finally, for the /static assets, you'd just have to rewrite your static links inside your NextJS app, i.e. turn



          <img src='/static/mylogo.svg' />


          to



          <img src=`$PROXY_PATH/static/mylogo.svg` />


          And the path rewrite on the proxy end should handle it correctly.
          With this, you could define PROXY_PATH at the project scope in a separate config file or load it from an environment variable.






          share|improve this answer

























          • Thank you so much to answer it! However, I guess that it is not the solution that I'm looking for :( ... Basically for two reasons: (1) The idea of the proxy is to have different projects running on different subpaths, and we can have conflicts routing paths like /static... (2) Your solution works fine to load the page with static files, however, navigating with next.js is starting from / and not from /example. I would like a solution touching only the next.js part, and not the proxy part. Is it not possible? :O Anyway thank you so much! I appreciate a lot your effort.

            – Aral Roca
            yesterday






          • 1





            @AralRoca I totally understand. As I said in my opening comment, I don't think NextJS plays nicely with a subpath proxy. There is however one thing you could do, and that would be to create your own MyLink component (inherited from Next's Link) and prepend your subpath to all links. But you'll still have to deal with the /static and build directories...

            – Jaxx
            16 hours ago











          • @AralRoca I've updated my answer with an additional configuration on the NextJS end, which would help with the build directory and the page links, but the /static assets directory remains an issue. Perhaps it could be handled with a custom server route on the NextJS side?

            – Jaxx
            15 hours ago











          • @AralRoca see my latest update for a possible (and simple) solution to the /static assets directory

            – Jaxx
            14 hours ago













          1












          1








          1







          As a caveat, I'll start by saying that I don't believe NextJS plays nice with proxies, especially on a subpath.



          That being said, the following should work, with limitations :



          const express = require('express')
          const proxy = require('http-proxy-middleware')

          const options =
          target:'http://localhost:3000/',
          pathRewrite:
          '^/example': ''


          const exampleProxy = proxy(options)
          const app = express()

          app.use(['/example', '/_next', '/static'], exampleProxy)
          app.listen(8000)


          The pathRewrite option makes sure /example/xyz on the proxy redirects to /xyz on your NextJS server.



          You need to proxy /_next (or whatever you renamed your build directory to) so that your page finds all the built assets (scripts, stylesheets, webpack chunks, etc.). If you inspect any of your Next's project pages you'll see that these assets links are absolute, hence the need to proxy that directory as well.



          You need to proxy /static for the same reason, except that directory is meant to hold your static NextJS assets (images, etc.).



          You'll also notice your page links in Next are usually absolute as well (I know mine are in all my projects).



          All the above is the reason why I stated that, in my opinion, NextJS isn't really suited for a subpath proxy usage.



          Update:



          You can add the following config in your next.config.js file at the root of your NextJS project:



          module.exports = 
          assetPrefix: '/example'



          This will prepend /example to all the built assets, so instead of /_next/pages/xyz you will link to /example/_next/pages/xyz. With this update you can remove the /_next proxy on the proxy side and your buildable assets (scripts, stylesheets, etc.) should still load.



          Regarding the navigational (i.e. 'page') links within your NextJS app, as stated in my comment, you could setup your own version of Link and prepend your subpath:



          import Link from 'next/link'

          // for proxied server
          const PROXY_PATH= '/example'
          // for non-proxied server
          // const PROXY_PATH= ''

          export default MyLink = ( as, children, ...props ) => <Link ...props as=`$PROXY_PATH$as`>children</Link>


          You'd have to make sure all your MyLink components define an as prop. You don't want to change the href prop itself (the link as it is), only the as prop (the link as it appears).



          Finally, for the /static assets, you'd just have to rewrite your static links inside your NextJS app, i.e. turn



          <img src='/static/mylogo.svg' />


          to



          <img src=`$PROXY_PATH/static/mylogo.svg` />


          And the path rewrite on the proxy end should handle it correctly.
          With this, you could define PROXY_PATH at the project scope in a separate config file or load it from an environment variable.






          share|improve this answer















          As a caveat, I'll start by saying that I don't believe NextJS plays nice with proxies, especially on a subpath.



          That being said, the following should work, with limitations :



          const express = require('express')
          const proxy = require('http-proxy-middleware')

          const options =
          target:'http://localhost:3000/',
          pathRewrite:
          '^/example': ''


          const exampleProxy = proxy(options)
          const app = express()

          app.use(['/example', '/_next', '/static'], exampleProxy)
          app.listen(8000)


          The pathRewrite option makes sure /example/xyz on the proxy redirects to /xyz on your NextJS server.



          You need to proxy /_next (or whatever you renamed your build directory to) so that your page finds all the built assets (scripts, stylesheets, webpack chunks, etc.). If you inspect any of your Next's project pages you'll see that these assets links are absolute, hence the need to proxy that directory as well.



          You need to proxy /static for the same reason, except that directory is meant to hold your static NextJS assets (images, etc.).



          You'll also notice your page links in Next are usually absolute as well (I know mine are in all my projects).



          All the above is the reason why I stated that, in my opinion, NextJS isn't really suited for a subpath proxy usage.



          Update:



          You can add the following config in your next.config.js file at the root of your NextJS project:



          module.exports = 
          assetPrefix: '/example'



          This will prepend /example to all the built assets, so instead of /_next/pages/xyz you will link to /example/_next/pages/xyz. With this update you can remove the /_next proxy on the proxy side and your buildable assets (scripts, stylesheets, etc.) should still load.



          Regarding the navigational (i.e. 'page') links within your NextJS app, as stated in my comment, you could setup your own version of Link and prepend your subpath:



          import Link from 'next/link'

          // for proxied server
          const PROXY_PATH= '/example'
          // for non-proxied server
          // const PROXY_PATH= ''

          export default MyLink = ( as, children, ...props ) => <Link ...props as=`$PROXY_PATH$as`>children</Link>


          You'd have to make sure all your MyLink components define an as prop. You don't want to change the href prop itself (the link as it is), only the as prop (the link as it appears).



          Finally, for the /static assets, you'd just have to rewrite your static links inside your NextJS app, i.e. turn



          <img src='/static/mylogo.svg' />


          to



          <img src=`$PROXY_PATH/static/mylogo.svg` />


          And the path rewrite on the proxy end should handle it correctly.
          With this, you could define PROXY_PATH at the project scope in a separate config file or load it from an environment variable.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 14 hours ago

























          answered yesterday









          JaxxJaxx

          1,7341615




          1,7341615












          • Thank you so much to answer it! However, I guess that it is not the solution that I'm looking for :( ... Basically for two reasons: (1) The idea of the proxy is to have different projects running on different subpaths, and we can have conflicts routing paths like /static... (2) Your solution works fine to load the page with static files, however, navigating with next.js is starting from / and not from /example. I would like a solution touching only the next.js part, and not the proxy part. Is it not possible? :O Anyway thank you so much! I appreciate a lot your effort.

            – Aral Roca
            yesterday






          • 1





            @AralRoca I totally understand. As I said in my opening comment, I don't think NextJS plays nicely with a subpath proxy. There is however one thing you could do, and that would be to create your own MyLink component (inherited from Next's Link) and prepend your subpath to all links. But you'll still have to deal with the /static and build directories...

            – Jaxx
            16 hours ago











          • @AralRoca I've updated my answer with an additional configuration on the NextJS end, which would help with the build directory and the page links, but the /static assets directory remains an issue. Perhaps it could be handled with a custom server route on the NextJS side?

            – Jaxx
            15 hours ago











          • @AralRoca see my latest update for a possible (and simple) solution to the /static assets directory

            – Jaxx
            14 hours ago

















          • Thank you so much to answer it! However, I guess that it is not the solution that I'm looking for :( ... Basically for two reasons: (1) The idea of the proxy is to have different projects running on different subpaths, and we can have conflicts routing paths like /static... (2) Your solution works fine to load the page with static files, however, navigating with next.js is starting from / and not from /example. I would like a solution touching only the next.js part, and not the proxy part. Is it not possible? :O Anyway thank you so much! I appreciate a lot your effort.

            – Aral Roca
            yesterday






          • 1





            @AralRoca I totally understand. As I said in my opening comment, I don't think NextJS plays nicely with a subpath proxy. There is however one thing you could do, and that would be to create your own MyLink component (inherited from Next's Link) and prepend your subpath to all links. But you'll still have to deal with the /static and build directories...

            – Jaxx
            16 hours ago











          • @AralRoca I've updated my answer with an additional configuration on the NextJS end, which would help with the build directory and the page links, but the /static assets directory remains an issue. Perhaps it could be handled with a custom server route on the NextJS side?

            – Jaxx
            15 hours ago











          • @AralRoca see my latest update for a possible (and simple) solution to the /static assets directory

            – Jaxx
            14 hours ago
















          Thank you so much to answer it! However, I guess that it is not the solution that I'm looking for :( ... Basically for two reasons: (1) The idea of the proxy is to have different projects running on different subpaths, and we can have conflicts routing paths like /static... (2) Your solution works fine to load the page with static files, however, navigating with next.js is starting from / and not from /example. I would like a solution touching only the next.js part, and not the proxy part. Is it not possible? :O Anyway thank you so much! I appreciate a lot your effort.

          – Aral Roca
          yesterday





          Thank you so much to answer it! However, I guess that it is not the solution that I'm looking for :( ... Basically for two reasons: (1) The idea of the proxy is to have different projects running on different subpaths, and we can have conflicts routing paths like /static... (2) Your solution works fine to load the page with static files, however, navigating with next.js is starting from / and not from /example. I would like a solution touching only the next.js part, and not the proxy part. Is it not possible? :O Anyway thank you so much! I appreciate a lot your effort.

          – Aral Roca
          yesterday




          1




          1





          @AralRoca I totally understand. As I said in my opening comment, I don't think NextJS plays nicely with a subpath proxy. There is however one thing you could do, and that would be to create your own MyLink component (inherited from Next's Link) and prepend your subpath to all links. But you'll still have to deal with the /static and build directories...

          – Jaxx
          16 hours ago





          @AralRoca I totally understand. As I said in my opening comment, I don't think NextJS plays nicely with a subpath proxy. There is however one thing you could do, and that would be to create your own MyLink component (inherited from Next's Link) and prepend your subpath to all links. But you'll still have to deal with the /static and build directories...

          – Jaxx
          16 hours ago













          @AralRoca I've updated my answer with an additional configuration on the NextJS end, which would help with the build directory and the page links, but the /static assets directory remains an issue. Perhaps it could be handled with a custom server route on the NextJS side?

          – Jaxx
          15 hours ago





          @AralRoca I've updated my answer with an additional configuration on the NextJS end, which would help with the build directory and the page links, but the /static assets directory remains an issue. Perhaps it could be handled with a custom server route on the NextJS side?

          – Jaxx
          15 hours ago













          @AralRoca see my latest update for a possible (and simple) solution to the /static assets directory

          – Jaxx
          14 hours ago





          @AralRoca see my latest update for a possible (and simple) solution to the /static assets directory

          – Jaxx
          14 hours ago



















          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%2f55022306%2fnext-js-under-a-proxy-with-different-path%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







          Popular posts from this blog

          Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

          Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

          Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved