You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
beta.11-webpack: No custom server routes possible? #1562
OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)
Windows 7
Versions. Please run ng --version. If there's nothing outputted, please run
in a Terminal: node --version and paste the result here:
angular-cli: 1.0.0-beta.11-webpack (on node v6.3.1)
Repro steps. Was this an app that wasn't created using the CLI? What change did you
do on your code? etc.
Added server/ folder
Added server/index.ts file
The log given by the failure. Normally this include a stack trace and some
more information.
No failure, but the index.ts didnt get executed.
Mention any other details that might be useful.
With the new build system, how can you install custom server routes?
@niklas-dahl and others with this problem/question:
We have found the easiest answer is to stop trying to make your front-end-development server (for example "ng serve") proxy to your API-server, and instead proxy the other way. Add a small feature to your API server to make it proxy to your front-end-development server. Depending on your server platform, this can take as little as a few lines of code. (For example, this is true with Node.)
@kylecordes@niklas-dahl Proxying from the backend is possible if we have control over the backend. But what if the backend is developed by a different team who are slow or negative to such propositions? In such cases we need to be able to proxy from the frontend dev server.
@costis and others - here is a further workaround, for that situation (unfixable backend), or other more complex situations beyond what a future CLI proxy setting will handle:
You have a computer, an infinitely programmable device. You can make your own development proxy, perhaps 15 lines of Node code, and proxy each kind of request however you need:
proxy API requests to your backend
proxy client asset requests to CLI ng serve
handle any other needed endpoints - for example, perhaps you are working on client code which needs a new backend API which does not exist yet; you could serve those with placeholder data
@niklas-dahl you're right that it worked previously, but only because it was a part of the ember-cli functionality. I think it was removed when we moved to webpack because that changed the server.
I don't personally think it makes a whole lot of sense to serve the app and the API from the same server/subdomain, but understand that some setups do that. #1487 re-adds the webpack proxy, but doesn't give you the mini-api functionality. You can proxy to a simple API server though.
Activity
filipesilva commentedon Aug 15, 2016
I need some more details here. What are you trying to do specifically?
niklas-dahl commentedon Aug 15, 2016
In the older angular-cli versions(1.0.0-beta.9) you could add an
server/index.js:module.exports = function(app) { app.get('/api', (req, res) => res.send('Welcome to the api')); }Running
ng servewould then execute this script and pass it its (express?) router object.Navigating to
localhost:4200/apiwould then give youWelcome to the api.niklas-dahl commentedon Aug 15, 2016
basically I need a way to integrate my backend server during development :)
kylecordes commentedon Aug 15, 2016
@niklas-dahl and others with this problem/question:
We have found the easiest answer is to stop trying to make your front-end-development server (for example "ng serve") proxy to your API-server, and instead proxy the other way. Add a small feature to your API server to make it proxy to your front-end-development server. Depending on your server platform, this can take as little as a few lines of code. (For example, this is true with Node.)
niklas-dahl commentedon Aug 15, 2016
@kylecordes this is actually a great idea, thank you, never thought about this.
Maby a small hint in the README would help a lot of people.
But still a bit strange that this worked in earlier version of the cli..
costis commentedon Aug 16, 2016
@kylecordes @niklas-dahl Proxying from the backend is possible if we have control over the backend. But what if the backend is developed by a different team who are slow or negative to such propositions? In such cases we need to be able to proxy from the frontend dev server.
kylecordes commentedon Aug 16, 2016
@costis and others - here is a further workaround, for that situation (unfixable backend), or other more complex situations beyond what a future CLI proxy setting will handle:
You have a computer, an infinitely programmable device. You can make your own development proxy, perhaps 15 lines of Node code, and proxy each kind of request however you need:
filipesilva commentedon Aug 23, 2016
@niklas-dahl you're right that it worked previously, but only because it was a part of the
ember-clifunctionality. I think it was removed when we moved to webpack because that changed the server.I don't personally think it makes a whole lot of sense to serve the app and the API from the same server/subdomain, but understand that some setups do that. #1487 re-adds the webpack proxy, but doesn't give you the mini-api functionality. You can proxy to a simple API server though.
angular-automatic-lock-bot commentedon Sep 6, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.