mgechev / angular-seed

🌱 [Deprecated] Extensible, reliable, modular, PWA ready starter project for Angular (2 and beyond) with statically typed build and AoT compilation
https://mgechev.github.io/angular-seed
MIT License
4.57k stars 1.45k forks source link

Data.json 404 on Azure. Also how to integrate NodeJS API into this seed project? #1468

Closed kahanu closed 8 years ago

kahanu commented 8 years ago

I've been able to successfully deploy the dist/prod folder to Azure. The only issue I have is that the data.json file was not found. That sounds to me like it's a server config issue not allowing json files to be served. Is that reasonable, or is it something that was missed when building and compiling the code?

I used npm run build.prod

Also, I'd like to integrate a NodeJS API into this seed project. Are there any suggestions or reference code anywhere to integrate a NodeJS API into this seed project?

mgechev commented 8 years ago

Make sure data.json is located in the right directory after you deploy to production.

In order to develop a node.js API you can use express or hapi for instance. You can take a look at both projects here and here.

There's nothing seed-specific that you need to do, it's just a standard configuration - seed running in dev server and communicating with the RESTful API using CORS.

Good luck!

kahanu commented 8 years ago

I haven't moved the location of the /assets/data.json file. Wherever the npm run build.prod put it, was where it was when deployed to Azure.

Re: NodeJS API - I've already built it, so it wasn't how to build it, but how to integrate both an API and Angular 2 into the same project and have the server launch them both.

I understand that Angular 2 is very new and there's not many good examples of how to work with it with other frameworks, like the MEAN stack. That's what is getting me a little stumped.

The reason I'm asking about if it's possible to integrate the API into the same project (code base) as the Angular 2 project is really to save on costs for hosting. This way I only need to pay for one hosting account, instead of two, one for the Angular 2 app, and one for the API. For many of us, costs is a big concern.

BTW, I really do like your seed project. After getting my head around what it does, it's great!

mgechev commented 8 years ago

The API server should be in a different project, not the seed. Yes, I completely understand you about the lack of examples at this point.

Showing how to build a simple API server and integrate it with Angular seed is something that we will show in a blog post next week.

kahanu commented 8 years ago

Yeah, I just created Azure accounts for the separate Angular 2 project and NodJS API project. I've tested it with MongoDB and they work perfectly. This is the way I prefer the setup, but my client is not so happy about higher costs for hosting. I try telling him the "separation of concerns" blah blah blah, and his eyes glaze over. It doesn't matter to him, but he really wants the app to work, and I told him it does and it will be easy to maintain this way. For the time being he's happy.

I look forward to the blog post.

c-mysec commented 7 years ago

there is an absolute url reference in sample name-list.service.ts that prevents from deploying under a different location than root folder.

get(): Observable<string[]> { return this.http.get('/assets/data.json') .map((res: Response) => res.json()) // .do(data => console.log('server data:', data)) // debug .catch(this.handleError); }

this code can cause "data.json 404"

pragatir commented 6 years ago

I had to manually add a web.config in 'dist/prod' with the following to make it work. `

` @mgechev is there a way to always include web.config as is during the build at the root level? Similar to what angular-cli does here