Skip to content

beta.11-webpack: No custom server routes possible? #1562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
niklas-dahl opened this issue Aug 5, 2016 · 9 comments
Closed

beta.11-webpack: No custom server routes possible? #1562

niklas-dahl opened this issue Aug 5, 2016 · 9 comments
Labels
needs: more info Reporter must clarify the issue

Comments

@niklas-dahl
Copy link
Contributor

  1. OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)
    Windows 7
  2. 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)
  3. 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
  4. 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.
  5. Mention any other details that might be useful.
    With the new build system, how can you install custom server routes?

Thanks! We'll be in touch soon.

@filipesilva filipesilva added the needs: more info Reporter must clarify the issue label Aug 15, 2016
@filipesilva
Copy link
Contributor

I need some more details here. What are you trying to do specifically?

@niklas-dahl
Copy link
Contributor Author

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 serve would then execute this script and pass it its (express?) router object.

Navigating to localhost:4200/api would then give you Welcome to the api.

@niklas-dahl
Copy link
Contributor Author

basically I need a way to integrate my backend server during development :)

@kylecordes
Copy link

@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
Copy link
Contributor Author

@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
Copy link

costis commented 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
Copy link

@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

@filipesilva
Copy link
Contributor

@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.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs: more info Reporter must clarify the issue
Projects
None yet
Development

No branches or pull requests

5 participants