我在wampserver中的我的angular 7应用程序有问题
我做了这个
{
"/api": {
"target": "http://localhost:3000",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
}
"start": "ng serve --proxy-config proxy.conf.json"
我的应用程序将其退还给我
General
Request URL: http://localhost/api
Request Method: GET
Status Code: 404 Not Found
Remote Address: [::1]:80
Referrer Policy: no-referrer-when-downgrade
Response Headers
Connection: Keep-Alive
Content-Length: 286
Content-Type: text/html; charset=iso-8859-1
Date: Thu, 10 Jan 2019 07:08:40 GMT
Keep-Alive: timeout=5, max=99
Server: Apache/2.4.35 (Win32) PHP/7.2.10
Request Headers
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: es-ES,es;q=0.9
Connection: keep-alive
Host: localhost
Referer: http://localhost/vdfrontend/
我在项目目录中使用了htacces文件,还修改了虚拟主机文件
htaccess文件包含下一个信息
<IfModule mod_rewrite.c>
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html
# to allow html5 state links
RewriteRule ^ index.html [L]
</IfModule>
虚拟主机文件包含下一个信息
# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName localhost
DocumentRoot "${INSTALL_DIR}/www/vdfrontend"
<Directory "${INSTALL_DIR}/www/vdfrontend">
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html
# to allow html5 state links
RewriteRule ^ index.html [L]
</Directory>
</VirtualHost>
我的应用程序再次将它退还给我
General
Request URL: http://localhost/api
Request Method: GET
Status Code: 404 Not Found
Remote Address: [::1]:80
Referrer Policy: no-referrer-when-downgrade
Response Headers
Connection: Keep-Alive
Content-Length: 286
Content-Type: text/html; charset=iso-8859-1
Date: Thu, 10 Jan 2019 07:08:40 GMT
Keep-Alive: timeout=5, max=99
Server: Apache/2.4.35 (Win32) PHP/7.2.10
Request Headers
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: es-ES,es;q=0.9
Connection: keep-alive
Host: localhost
Referer: http://localhost/vdfrontend/
由于这个原因我的应用无法正常工作,如何解决此问题?
答案 0 :(得分:1)
添加三个新回复可能不是一个好主意-最好将您的其他信息放在原始帖子中:(
无论如何:
您说您的“ api”正在端口3000上运行。但是您的跟踪显示“某人”(您的浏览器正在运行Angular应用程序?)正在运行GET http://localhost/api
,端口80。
出现HTTP 404错误!
潜在的解决方案:
忘记代理,忘记NodeJS-只需在WAMP / Apache服务器上部署您的API。那应该可以解决问题-一切都将在端口80上。
或者,考虑在NodeJS上同时提供Angular和您的API(而无需考虑WAMP和代理)。
如果您确实要在生产中使用两台服务器(WAMP和NodeJS),则应考虑使用CORS:
How to handle CORS in an Angular2 and Node/Express Applications
另一个链接可能会有所帮助:
'希望有帮助..PSM
您 MAY 如果确实希望将Apache配置为Node API服务器的反向代理。问题是它不起作用。您的Angular应用正在尝试连接到端口80上的“ api”;它实际上位于端口3000上。另一个麻烦是,Apache对名称“不客气”:也许应该是“ / api /”而不是“ / api”(例如,看起来here)。
我的建议是通过将所有内容移到一个或另一个服务器上来简化配置,消除对代理的需求,并消除任何潜在的跨域Javascript问题。
以下还有一些其他链接可能会有所帮助: