我最近一直在集成 redux-toolkits createListenerMiddleware但目前有点陷入困境。我正在尝试输入一些“侦听器条目”,但似乎无法管理它。智能感知对我来说没有意义,我在文档或网上找不到任何与此相关的示例。目标是输入listenerApi参数,以便我可以使用该getState()函数而无需进行任何类型转换。
有什么简单的方法可以实现这一目标吗?
任何帮助将不胜感激。
listenerMiddleware.startListening({
actionCreator: toggleSomething, // Action generator from reducer createSlice
effect: async (
action: AnyAction,
listenerApi: ListenerEffectAPI<AppState, Dispatch> // Trying to type this in some way :[
): Promise<void> => {
const state = (await listenerApi.getState()) as AppState; // TODO: type this better
},
});
Run Code Online (Sandbox Code Playgroud) 尚未能够深入了解此问题的根本原因,但我正在尝试使用 NextJS 12.2.2 实现文员身份验证,并且我在开发环境中一切正常。然而,当我进入生产环境时,由于以下错误,我的网站在加载时立即崩溃:
ReferenceError: __import_unsupported is not defined
at (vc/edge/function:14:2050)
at (vc/edge/function:14:656)
at (vc/edge/function:14:3107)
at (vc/edge/function:14:656)
at (vc/edge/function:67:13871)
at (vc/edge/function:14:656)
at (vc/edge/function:67:15731)
at (vc/edge/function:14:656)
at (vc/edge/function:67:27265)
at (vc/edge/function:14:656)
ReferenceError: __import_unsupported is not defined
at (external root " __import_unsupported('buffer')":1:0)
at (webpack/bootstrap:21:0)
at (node_modules/rfc4648/lib/index.mjs:11:15)
at (webpack/bootstrap:21:0)
at (node_modules/@clerk/nextjs/dist/server/clerk.js:5:18)
at (webpack/bootstrap:21:0)
at (node_modules/@clerk/nextjs/dist/server/index.js:4:21)
at (webpack/bootstrap:21:0)
at (node_modules/@clerk/nextjs/server.js:1:0)
at (webpack/bootstrap:21:0)
Run Code Online (Sandbox Code Playgroud)
我的 Clerk middleware.js 文件:
import { withClerkMiddleware } from "@clerk/nextjs/server";
import { NextResponse } from "next/server";
export default withClerkMiddleware((req) => {
return NextResponse.next(); …Run Code Online (Sandbox Code Playgroud) 我是Slim Framework和PHP的新手.我无法使用它,如果我使用普通函数并使用"foo"作为参数,它可以工作,但不会像这样工作,即使文档使用几乎相同的东西http://docs.slimframework.com /
<?php
require 'Slim/Slim.php';
session_start();
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$foo = function() {
global $app;
if(!isset($_SESSION["user_id"])) {
$app->redirect("/redirecto/login");
} else {
echo "Authenticated";
}
}
$app->get("/", $foo, function() {
global $app;
$app->render('index.php');
});
$app->get("/login", function() use ($app) {
$app->render("login.php");
});
?>
Run Code Online (Sandbox Code Playgroud)
错误是
Parse error: syntax error, unexpected '$app' (T_VARIABLE) in C:\xampp\htdocs\redirecto\index.php on line 41
Run Code Online (Sandbox Code Playgroud)
($ app-> get("/",$ foo,function(){line)
是否可以X-Forwarded-For在weblogic的access.log日志文件中记录标题?
我正在使用具有多部分中间件的快速节点框架.设置multipart defer: true选项使我可以访问req.form路径,但它似乎不是多方Form对象的有效实例.它只是一个普通的旧JS对象.
问题是我无法使用表单对象上的multiparty文档中概述的功能.收听事件,解析表单等都不起作用.
我使用它作为建议而不是使用express的折旧bodyParser():
app.use(express.urlencoded());
app.use(express.json());
app.use(express.multipart({ limit: '900mb', defer: true }));
Run Code Online (Sandbox Code Playgroud)
在我的路线:
app.post('/api/videos/upload', isLoggedIn, function(req, res) {
var form = req.form;
form.on('progress', function(bytesReceived, bytesExpected) {
console.log(bytesReceived + ' / ' + bytesExpected);
});
Run Code Online (Sandbox Code Playgroud)
我在日志中得不到有关进展的任何信息.我看到的所有例子都假设这个表单对象是真正的交易而不仅仅是数据对象.他们有什么不同的做法?我错过了什么?
我已经看到建议编写我自己的中间件直接使用multiparty的解决方案.我考虑过这个,但是我在不同路径上使用多部分中间件用于不需要这种控制级别的其他形式.是否可以使用multipart并编写我自己的中间件只是为了上传?
如果我要走下一个兔子洞,我会解释我的最终目标.我想在上传开始之前检查预期的字节,这样我就可以立即将其踢回前端.没有理由用户在发现文件太大之前应该等待900MB上传.如果有人对如何实现其他方式有任何见解请分享.
如果有以下架构和中间件挂钩,而是find和findOne挂钩从来没有被调用.在save与update预期挂钩工作.根据Mongoose Middleware文档,这应该是可用的.
// define the schema for our recs model
var recSchema = mongoose.Schema({
dis: String, // rec display
mod: String // modified date (HAYSTACK FORMAT)
}, {
strict: false
});
// create the model for recs
var model = recsdb.model('recs', recSchema);
recSchema.pre('save', function(next) {
this.mod = HDateTime.now(HTimeZone.UTC).toZinc();
next();
});
recSchema.pre('update', function(next) {
this.mod = HDateTime.now(HTimeZone.UTC).toZinc();
next();
});
recSchema.pre('find', function() {
console.log("Pre Find");
});
recSchema.pre('findOne', function() {
console.log("Pre Find One"); …Run Code Online (Sandbox Code Playgroud) 我正在尝试在注册后立即重定向用户以转到协议条款页面。
这是我的中间件课程:
class TermsMiddleware(object):
def process_request(self, request):
if request.user.profile.filled_terms is None:
return redirect(reverse('terms'))
Run Code Online (Sandbox Code Playgroud)
我收到以下错误,可以快速浏览一下我的服务器:
This webpage has a redirect loop
Run Code Online (Sandbox Code Playgroud)
我有一个带有fill_terms字段的Profile模型类。
我有一个术语模板,当我手动访问它时,它工作得很好。
这也是我的网址匹配器:
url(r'^terms/', 'hana.views.terms', name='terms')
Run Code Online (Sandbox Code Playgroud)
我如何摆脱这种重定向循环,并使用中间件将注册用户重定向到协议条款页面?
问题:我无法在中间件中找到{id}参数.我的中间件需要获取{id}参数,以验证Auth :: user()是否是指定组的所有者.
请求示例:groups/admin/open/4 - >将打开第4组.
是)我有的:
路线:
Route::post('groups/admin/open/{id}', 'GroupController@opengroup')->middleware(['auth','owner']);
Run Code Online (Sandbox Code Playgroud)
我的中间件('所有者')仍然是空的.
我尝试了什么:1.在函数中添加$ id参数(就像在控制器中一样),如下所示:
public function handle($request, /* Added -> */ $id, Closure $next)
{
dd(Input::get('id'));
return $next($request);
}
Run Code Online (Sandbox Code Playgroud)
这会返回一个错误:
Argument 3 passed to App\Http\Middleware\RedirectIfNotOwner::handle() must be an instance of Closure, none given
Run Code Online (Sandbox Code Playgroud)
最后,$ id的不同位置会导致错误:
Missing argument 3 for App\Http\Middleware\RedirectIfNotOwner::handle()
Run Code Online (Sandbox Code Playgroud)
我试过的2:我想过要改变我的网址
请求示例:groups/admin/open?groupparam = 4
并使用
Input::get('groupparam');
Run Code Online (Sandbox Code Playgroud)
但这迫使我改变我的控制器等.这仍然是一个选择.
问的理由:此外我相信Laravel也有能力在中间件中检索{id} params,非常漂亮.我只是不知道如何.
你能帮助我吗?
谢谢,
Eltyer
在web.php中,随着发出HTTP请求的子域类型,我在中间件中切换了Postgres模式。这条路:
Route::group(
[
'domain' => '{tenant}.' . config('app.url'),
'middleware' => 'select-schema'
],
function () {
$this->get('/', 'HomeController@index')->middleware('auth');
}
);
Run Code Online (Sandbox Code Playgroud)
在选择模式中间件中,我这样做。这可以正常工作。(不用担心)
DB::select('SET search_path TO ' . {tenant});
Run Code Online (Sandbox Code Playgroud)
我的主要问题是:migrations对于public方案和任何其他方案,我都有所不同individual tenant。在individual tenant我有users桌子。一旦我登录,就会弹出此错误。
SQLSTATE [42P01]:未定义表:7错误:关系“用户”不存在
主要问题是
$this->get('/', 'HomeController@index')->middleware('auth');
Run Code Online (Sandbox Code Playgroud)
该模型运行良好,但中间件auth先执行 select-schema
我该如何订购? select-schema然后auth
我有一个Express应用程序,我正在尝试将所有中间件放在自己的文件中.一些中间件函数需要该db对象,而另一些则不需要.
这对于那些不需要的功能非常简单的db对象,但由于我下面的代码结构,我怎么可以参照db对象doesNotNeedDbParam,因为它已经拥有PARAMS req,res和next?
somefile.js:
const router = express.Router()
const doesNotNeedDbParam = require('./middleware')().doesNotNeedDbParam
function foo () {
// Currently I have to call require and pass in the db object here b/c
// it's not set when requiring the function doesNotNeedDbParam
router.use(require('./middleware')(db).needsDbParam // <-- Is there a better way to do this so that I can require the file above and pass the db object in when it's …Run Code Online (Sandbox Code Playgroud) middleware ×10
node.js ×3
express ×2
laravel ×2
php ×2
clerk ×1
django ×1
find ×1
javascript ×1
laravel-5 ×1
mongoose ×1
multi-tenant ×1
multipart ×1
next.js ×1
postgresql ×1
python ×1
reactjs ×1
redirect ×1
redux ×1
routes ×1
slim ×1
typescript ×1
upload ×1
weblogic ×1
weblogic11g ×1