Giter Club home page Giter Club logo

Comments (4)

johnsken-jerry avatar johnsken-jerry commented on August 15, 2024 2

The problem is found because the token interceptor is set up in the project, and all HTTP requests are sent out after the interceptor processing, and the server does not seem to support the token related operations.

from universal-starter.

vadjs avatar vadjs commented on August 15, 2024

You should use TransferState. You can read more about it here. Also you can watch how to use requests with SSR in this file.

from universal-starter.

johnsken-jerry avatar johnsken-jerry commented on August 15, 2024

I have callback according to the official HTTP, but when I move my project to demo, there will be no HTTP callback.
Encapsulated http.client.ts

import { TransferHttpService } from '@gorniv/ngx-transfer-http';
export class _HttpClient {
    constructor(private http: TransferHttpService) { }

    get(url: string, params?: any): Observable<any> {
        return this.http
            .get(url, {
                params: this.parseParams(params)
            })
            .catch((res) => {
                return res;
            });
    }
}

home.component.ts

import { _HttpClient } from '@core/services/http.client';
...
constructor(private http: TransferHttpService) {}
ngOnInit() {
   this.http.get(`http://xxxx.xx/searchHasAcceptTest`).subscribe((res: any) => { // not callback
      console.log(res)
    }, error => {
      console.error("Error", error);
    });
 }
...

home.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { _HttpClient } from '@core/services/http.client';
import { HomeRoutes } from './home.routing';
import { HomeComponent } from './home.component';

@NgModule({
  imports: [
    CommonModule,
    HomeRoutes,
    TranslateModule
  ],
  providers: [
    _HttpClient
  ],
  declarations: [HomeComponent]
})
export class HomeModule { }

package.json

{
  "name": "universal-demo",
  "version": "6.1.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "ssr": "npm run build:universal && npm run generate:prerender && npm run server",
    "ssr:debug": "ng build --aot=true --output-hashing=all --named-chunks=false --build-optimizer=true  && ng run universal-demo:server:dev && webpack && node server.js",
    "ssr:cw": "ng build --aot=true --output-hashing=all --named-chunks=false --build-optimizer=true --watch",
    "ssr:sw": "ng run universal-demo:server:dev --watch",
    "ssr:webpack": "webpack --watch",
    "ssr:server": "nodemon server.js",
    "build": "ng build",
    "build:server": "ng run universal-demo:server:production",
    "build:prod": "ng build --prod",
    "build:universal": "ng build --prod && ng run universal-demo:server:production && webpack --progress --colors",
    "server": "node server.js",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "build:prerender": "npm run build:universal && npm run generate:prerender",
    "generate:prerender": "node prerender.js"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "6.0.6",
    "@angular/common": "6.0.6",
    "@angular/compiler": "6.0.6",
    "@angular/core": "6.0.6",
    "@angular/forms": "6.0.6",
    "@angular/http": "6.0.6",
    "@angular/platform-browser": "6.0.6",
    "@angular/platform-browser-dynamic": "6.0.6",
    "@angular/pwa": "0.6.8",
    "@angular/router": "6.0.6",
    "@angular/service-worker": "6.0.6",
    "@gorniv/ngx-transfer-http": "2.0.1",
    "@ngrx/effects": "^6.0.1",
    "@ngrx/router-store": "^6.0.1",
    "@ngrx/store": "^6.0.1",
    "@ngrx/store-devtools": "^6.0.1",
    "@nguniversal/common": "6.0.0",
    "@nguniversal/express-engine": "6.0.0",
    "@nguniversal/module-map-ngfactory-loader": "6.0.0",
    "@ngx-meta/core": "6.0.0-rc.1",
    "@ngx-translate/core": "10.0.2",
    "@ngx-translate/http-loader": "3.0.1",
    "angular2-masonry": "^0.4.0",
    "cookie-parser": "1.4.3",
    "core-js": "2.5.7",
    "imagesloaded": "^4.1.4",
    "moment": "^2.22.2",
    "morgan": "^1.9.0",
    "ng-lazyload-image": "^4.0.0",
    "ng-zorro-antd": "0.6.6",
    "ngx-cookie-service": "1.0.10",
    "ngx-countdown": "^3.0.1",
    "ngx-infinite-scroll": "^6.0.1",
    "ngx-masonry": "^1.1.0",
    "ngx-pagination": "^3.1.1",
    "ngx-pipes": "^2.2.0",
    "ngx-qrcode2": "0.0.9",
    "node-fetch": "2.1.2",
    "rxjs": "6.2.1",
    "rxjs-compat": "^6.2.1",
    "rxjs-tslint": "0.1.4",
    "videogular2": "^6.2.1",
    "zone.js": "0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "0.6.8",
    "@angular-devkit/schematics": "^0.6.8",
    "@angular/cli": "6.0.8",
    "@angular/compiler-cli": "6.0.6",
    "@angular/language-service": "6.0.6",
    "@angular/platform-server": "6.0.6",
    "@types/jasmine": "2.8.8",
    "@types/jasminewd2": "2.0.3",
    "@types/node": "10.3.4",
    "codelyzer": "4.3.0",
    "jasmine-core": "3.1.0",
    "jasmine-spec-reporter": "4.2.1",
    "karma": "2.0.3",
    "karma-chrome-launcher": "2.2.0",
    "karma-cli": "1.0.1",
    "karma-coverage-istanbul-reporter": "2.0.1",
    "karma-jasmine": "1.1.2",
    "karma-jasmine-html-reporter": "1.1.0",
    "localstorage-polyfill": "^1.0.1",
    "nodemon": "1.17.5",
    "preboot": "^6.0.0-beta.4",
    "protractor": "5.3.2",
    "ssri": "6.0.0",
    "tslint": "5.10.0",
    "typescript": "2.7.2",
    "webpack-cli": "3.0.8"
  }
}

from universal-starter.

AbdiganiyevShakhmardan avatar AbdiganiyevShakhmardan commented on August 15, 2024

The problem is found because the token interceptor is set up in the project, and all HTTP requests are sent out after the interceptor processing, and the server does not seem to support the token related operations.

how to solve this problem? My post requests body are not be sending

from universal-starter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.