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
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
add a comment |
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
add a comment |
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
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
node.js proxy next.js
asked yesterday
Aral RocaAral Roca
1,80622446
1,80622446
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
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 ownMyLink
component (inherited from Next'sLink
) 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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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 ownMyLink
component (inherited from Next'sLink
) 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
add a comment |
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.
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 ownMyLink
component (inherited from Next'sLink
) 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
add a comment |
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.
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.
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 ownMyLink
component (inherited from Next'sLink
) 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
add a comment |
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 ownMyLink
component (inherited from Next'sLink
) 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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