I'm beginning to study node js and im trying to connect an ionic app with my backend nodejs app that i have created but im getting this error:
OPTIONS https://localhost:3000/insert net::ERR_SSL_PROTOCOL_ERROR
import { Component, OnInit } from '@angular/core';
import { Http } from '@angular/http';
import { map } from 'rxjs/operators';
@Component({
selector: 'app-cadastro-unidade',
templateUrl: './cadastro-unidade.page.html',
styleUrls: ['./cadastro-unidade.page.scss'],
})
export class CadastroUnidadePage implements OnInit {
constructor(private http: Http) { }
ngOnInit() {
}
InsereDados(){
let data = {
};
this.http.post('https://localhost:3000/insert', data).pipe(
map(res => res.json())
).subscribe(response => {
console.log('POST Response:', response);
});
}
}
app.get('/insert', function(req, res, next) {
var uri = "xxxx"
MongoClient.connect(uri,{ useNewUrlParser: true }, function(err,client){const collection = client.db("test").collection("teste");
console.log("connected");
var ins={DataEntrada:"x",DataSaida:"x",HorarioEntrada:"x",HorarioSaida:"x",Prontuario:"x",TipoSaida:"x"};
collection.insertOne(ins, function(err,res){
console.log("data inserted");
})
client.close();
})
res.render(res)
});
Port 3000 is commonly used for plain HTTP and not HTTPS and this is likely true in your setup too. It does not magically turn into HTTPS if you use https:// instead of http:// in the URL.
The error messages is a result of your client speaking the wrong protocol (HTTPS, i.e. HTTP over TLS) and that the answer from the server (plain HTTP, without TLS) is not the valid TLS message which is expected by the client - i.e. ERR_SSL_PROTOCOL_ERROR.
`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With