我有一个项目,它使用 angular 作为前端,后端有一个 Laravel API。我想利用 ng serve 的代理实时重新加载:
ng serve --proxy-config proxy.config.js
Run Code Online (Sandbox Code Playgroud)
这是 proxy.config.js 文件:
const PROXY_CONFIG = {
"/v2/*": {
"target": "http://local-laravel-api/",
"secure": false,
"pathRewrite": {
"^/v2": "/v2"
},
"logLevel": "debug",
"changeOrigin": true
}
}
module.exports = PROXY_CONFIG;
Run Code Online (Sandbox Code Playgroud)
Laravel API 具有身份验证。当我访问 localhost:4200 时,我得到“Not Authenticated”,这是因为在通过代理时浏览器中未设置 auth cookie。
如果我直接访问 API(在浏览器中访问 local-laravel-api),cookie 存在并且我通过了身份验证。
所以基本上,代理似乎没有接收 cookie(我不知道为什么)。
我在网上看到多个线程讨论相同的问题,我已经用尽了所有这些,但仍然无法访问 API。
有没有人有任何想法可以阐明这个问题?
任何帮助是极大的赞赏!
哪条路走得更好?
我应该将对象存储在会话中并将其从一个页面传递到另一个页面,还是应该在每次用户迁移到我的Web应用程序中的另一个页面时查询数据库?
如果我应该将我的对象存储在会话中,我该怎么做呢?我已尝试使用序列化和反序列化,但它不适合我...
谢谢你的帮助!
编辑:这是我的一些代码
Page 1:
include "user.php";
session_start();
$user = new user();
$user->$username = "Jason";
$_SESSION["user"] = $user;
header("Location: profile.php");
Page 2:
include "user.php";
session_start();
$user = new user();
$user = $_SESSION["user"];
echo $user->$username;
Run Code Online (Sandbox Code Playgroud)
没有结果.
我有一个Object基类,我有几个派生类,名为Item,Person和Location.
因为每个都是从Object派生的,所以我需要在每个头文件中包含Object.h,并且我在main中包含了所有派生类.
因为我这样做我得到重新定义错误.
我想知道的是包含这些文件以避免此错误的正确方法是什么?
谢谢!
编辑:
object.h
using namespace std;
class Object{
string name;
string description;
public:
Object();
Object(string name, string description);
void set_name(string name);
void set_description(string description);
string get_name();
string get_description();
~Object();
};
Run Code Online (Sandbox Code Playgroud)
item.h
using namespace std;
#include "object.h"
class Item : public Object{
public:
Item();
Item(string name, string description);
};
Run Code Online (Sandbox Code Playgroud)
locale.h文件
using namespace std;
#include "object.h"
class Locale : public Object{
public:
Locale();
Locale(string name, string description);
};
Run Code Online (Sandbox Code Playgroud)
main.cpp中
#include <iostream>
#include <string>
#include "locale.h"
#include "item.h"
using …Run Code Online (Sandbox Code Playgroud) add_action( 'delete_post', 'test_function' );
function test_function(){
echo "Hello!";
}
Run Code Online (Sandbox Code Playgroud)
"你好!" 我删除帖子时没有显示(这是一个自定义的帖子类型,但这不重要吗?).我该如何调试?
编辑:我不能把这些代码放在任何前端文件,如header.php或index.php,因为当我从后端删除一个帖子时,我将无法查看输出.解决这个问题的最佳方法是什么?
谢谢
action ×1
angular ×1
c++ ×1
cookies ×1
debugging ×1
header-files ×1
hook ×1
http-proxy ×1
laravel ×1
php ×1
redefinition ×1
session ×1
wordpress ×1