Node.js 无法加载资源:net::错误\u连接\u被拒绝:Nodejs
我有一个Node.js 无法加载资源:net::错误\u连接\u被拒绝:Nodejs,node.js,angular,typescript,express,bootstrap-4,Node.js,Angular,Typescript,Express,Bootstrap 4,我有一个bootstrap表单,用于angular 6应用程序和nodejs的电子邮件服务,我在应用程序中使用nodemailer发送电子邮件,不幸的是不起作用。我发现以下错误: 加载资源失败:net::ERR\u连接被拒绝::3000/contact/send:1 这是表格 <form [formGroup]="angForm" novalidate> <div class="message"> <h3> Write to us <
bootstrap
表单,用于angular 6
应用程序和nodejs
的电子邮件服务,我在应用程序中使用nodemailer
发送电子邮件,不幸的是不起作用。我发现以下错误:
加载资源失败:net::ERR\u连接被拒绝::3000/contact/send:1
这是表格
<form [formGroup]="angForm" novalidate>
<div class="message">
<h3> Write to us </h3>
</div>
<div class="form__top">
<div class="form__left">
<div class="form__group">
<input class="form__input form__input--name" type="text" formControlName="name" placeholder="name" #name>
</div>
<div *ngIf="angForm.controls['name'].invalid && (angForm.controls['name'].dirty || angForm.controls['name'].touched)" class="alert alert-danger">
<div *ngIf="angForm.controls['name'].errors.required">
Name is required.
</div>
</div>
<div class="form__group">
<input class="form__input form__input--email" type="email" formControlName="email" placeholder="email" #email>
</div>
<div *ngIf="angForm.controls['email'].invalid && (angForm.controls['message'].dirty || angForm.controls['message'].touched)"
class="alert alert-danger">
<div *ngIf="angForm.controls['message'].errors.required">
message is required.
</div>
</div>
</div>
<div class="form__right">
<div class="form__group">
<textarea class="form__input form__input--textarea" placeholder="Message" formControlName="message" #message
rows="3"></textarea>
</div>
<div *ngIf="angForm.controls['message'].invalid && (angForm.controls['message'].dirty || angForm.controls['message'].touched)"
class="alert alert-danger">
<div *ngIf="angForm.controls['message'].errors.required">
message is required.
</div>
</div>
</div>
</div>
<flash-messages></flash-messages>
<div class="form__down">
<div class="form__group">
<button (click)="sendMail(name.value, email.value, message.value)" [disabled]="angForm.pristine || angForm.invalid" class="form__input form__input--submit" name="submit" type="submit" value="SEND MESSAGE">SEND MESSAGE
</button>
</div>
</div>
</form>
更新
这是服务
import { Injectable } from '@angular/core';
import { Headers, Http, Response } from '@angular/http';
import { Jsonp } from '@angular/http';
@Injectable({
providedIn: 'root'
})
export class ContactService {
constructor(private http: Http) { }
sendEmail(name, email, message) {
const uri = 'http://localhost:3000/contact/send';
const obj = {
name: name,
email: email,
message: message,
};
return this.http.post(uri, obj);
}
}
我的代码中缺少什么
加载资源失败:net::ERR\u连接被拒绝::3000/contact/send:1
您的错误意味着您的客户端应用程序无法连接到nodejs服务器
修理
您的代码:
const uri = 'http://localhost:3000/contact/send';
如果nodejs服务器在本地主机上的端口3000上运行,则将正常工作
加载资源失败:net::ERR\u连接被拒绝::3000/contact/send:1
您的错误意味着您的客户端应用程序无法连接到nodejs服务器
修理
您的代码:
const uri = 'http://localhost:3000/contact/send';
如果nodejs服务器在本地主机上的端口3000上运行,则将正常工作 您是对的,但现在我有以下错误
home:1未能加载http://localhost:3000/contact/send: 对飞行前请求的响应未通过访问控制检查:请求的资源上不存在“访问控制允许来源”标头。起源'http://localhost:4200'因此不允许访问
我需要在代码中更改什么?新问题,新问题。特别是如果你已经接受了这个问题的答案:)@msbit在这里你去老板你的权利,但现在我有以下错误home:1未能加载http://localhost:3000/contact/send: 对飞行前请求的响应未通过访问控制检查:请求的资源上不存在“访问控制允许来源”标头。起源'http://localhost:4200'因此不允许访问
我需要在代码中更改什么?新问题,新问题。特别是如果你已经接受了这个问题的答案:)@msbit这里你去吧,老板
const uri = 'http://localhost:3000/contact/send';