'not found' error with proxy config in Angular 6

kursat sonmez

I work with .net Core Web API + Angular 6.

Angular port: 4200 and Web API port: 62633

I want to work with the proxy config in Angular 6 but always getting the same error. I have read the answers related to this problem but I cannot find a solution. source: https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/proxy.md

proxy.conf.js

const PROXY_CONFIG = {
    "/api": {
        "target": "http://localhost:62633",
        "secure": false,
        "pathRewrite": {
            "^/api": "http://localhost:62633"
        },
    }
}
module.exports = PROXY_CONFIG;

angular.json

"architect": {
...
"serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "projectname:build",
            "proxyConfig": "proxy.conf.js",
            "port": 4200
          },
          "configurations": {
            "production": {
              "browserTarget": "projectname:build:production"
            }
          }
        }...
}

account.service.ts

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

import { LoginDto } from '../../../dtos/account/accountDtos';
import { Observable } from 'rxjs';

@Injectable()
export class AccountService {
  constructor(private hC: HttpClient) { }

  login(loginModel: LoginDto): Observable<LoginDto> {
    return this.hC.post<LoginDto>('/api/login', loginModel);
  }
}

Result in the console:

zone.js:2969 POST http://localhost:4200/api/login 404 (Not Found)

HttpErrorResponse {headers: HttpHeaders, status: 404, statusText: "Not Found", url: "http://localhost:4200/api/login", ok: false, …}

I do not think so, however, the source of error, could it be related to packages? Thanks.

kursat sonmez

Problem is solved. Those who encounter the same error, please check your API :)

Also,

PROXY_CONFIG

"pathRewrite": {
            "^/api": ""
        },

and account.service.ts

login(loginModel: LoginDto): Observable<APIResult> {
    return this.hC.post<APIResult>('/api/account/login', loginModel.toJSON());
  }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Angular 6 setTimeout Module not found: Error: Can't resolve 'timers'

Update to Angular v6 - Module not found: Error: Can't resolve 'fs'

Different proxy config based on environment in Angular 2 CLI

How to deploy angular 2 application to HTTP server with proxy-config

Angular 6: Module not found error regarding RxJs

explain proxy.config.json features angular 5

Angular migration (from 4 to 6) e2e --proxy-config not working

ERROR Error: StaticInjectorError Angular 6

angular injector error with config()

Why image not found error come in angular 6?

Importing jquery in Angular6 : Module not found: Error: Can't resolve 'jquery'

Service name not found in angular 6

Angular - ERROR ReferenceError: config is not defined

Angular 6 - Module not found: Error: Can't resolve 'http' in

Angular 6 Application Productions build gets successfully but on load throws error No component factory found for t

Nginx reverse proxy config - 404 not found

Error in Entry Module not found - in Webpack Config file

Configuring proxy in karate-config.js get parse error

Module Not Found Error: No module named config

ERROR in "path" Module not found: Error: Can't resolve - Angular 6 Webpack

Fatal error:class Config not found in php?

Unable to do post request with HttpClient in angular using proxy config with solution

Angular 6 Docker Build - ERROR in The Angular Compiler requires TypeScript >=2.7.2 and <2.8.0 but 2.8.3 was found instead

Ionic error - Exec proxy not found for :: Ftp :: connect

Angular proxy config to change url

config proxy in angular cli

Is it possible to access localstorage from Angular proxy.config.js file?

Angular proxy config not having any effect

Angular 15: Proxy Config not Working or Deducted