proxy in angular universal
proxy in angular universal
I'm on the projects that were made with Angular Universal.
I need to change blog.mywebsite.com
to mywebsite.com/blog
for SEO, I used proxy-config in ng start
, like code below, it works correctly but it doesn't work when I run build:ssr
blog.mywebsite.com
mywebsite.com/blog
ng start
build:ssr
there is no error in the built project, just after running with node dist / server.js
show website but I call mywebsite.com / mag
I redirect to 404 page, while there is no problem in npm start
node dist / server.js
mywebsite.com / mag
npm start
"scripts": {
"ng": "ng",
"build": "ng build --prod",
"start": "ng serve -o --proxy-config src/proxy.conf.json ",
"extract": "ng xi18n --output-path=locale",
"build:ssr": "npm run build:client-and-server-bundles && npm run
webpack:server ",
"serve:ssr": "node dist/server.js",
"build:client-and-server-bundles": "ng build --prod && ng run
angular.io-example:server",
"webpack:server": "webpack --config webpack.server.config.js --devServer --
progress --colors"
},
and this is my config-proxy-file:
{
"/mag": {
"target": {
"host": "mag.mywebsite.com",
"protocol": "http:",
"port": 80
},
"secure": false,
"changeOrigin": true,
"logLevel": "info",
"pathRewrite": {"^/mag" : ""}
}
}
The proxy is for local dev, not deployment.
– jonrsharpe
Jul 1 at 7:53
No, there is no error in the build project, just after running with node
dist / server.js
show website but I call mywebsite.com / mag
i redirect to 404 page, whiles there is not problem in npm start
– Alireza Varmaghani
Jul 1 at 8:25
dist / server.js
mywebsite.com / mag
npm start
The
proxy
configuration is intended to proxy calls when running the dev server via ng serve
. After you run ng build
you are responsible for the web server and its configurations– Vikas
Jul 1 at 9:03
proxy
ng serve
ng build
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What do you mean by "it doesn't work"? Is there any error message given? What happens instead?
– Nico Haase
Jul 1 at 7:51