我从https://devdactic.com/restful-api-user-authentication-1/学习了教程.但是这部分我得到了错误
passport.use(new JwtStrategy(opts, function(jwt_payload, done)
Run Code Online (Sandbox Code Playgroud)
运行节点"server.js"时出现错误
/home/chibi/Documents/connect/project/node_modules/passport-jwt/lib/strategy.js:39
throw new TypeError('JwtStrategy requires a function to retrieve jwt f
^
TypeError: JwtStrategy requires a function to retrieve jwt from requests (see option jwtFromRequest)
at new JwtStrategy (/home/chibi/Documents/connect/project/node_modules/passport-jwt/lib/strategy.js:39:15)
at module.exports (/home/chibi/Documents/connect/project/config/passport.js:10:16)
at Object.<anonymous> (/home/chibi/Documents/connect/project/server.js:30:29)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
Run Code Online (Sandbox Code Playgroud)
解决办法是什么?
我已经使用标准进程工作了API,但我想data从JSON输出中删除命名空间.我看到我需要实现ArraySerializer,我已经完成了分形文档,但我无法找到我需要在Laravel 5.2中添加它的地方
我找到了这个答案,但我只是在我注释掉的代码行中得到了相同的输出:
class TrackController extends ApiController
{
public function index()
{
$tracks = Track::all();
//return $this->respondWithCollection($tracks, new TrackTransformer);
// Same response as the commented out line above
$response = new \League\Fractal\Resource\Collection($tracks, new TrackTransformer);
$manager = new \League\Fractal\Manager();
$manager->setSerializer(new \League\Fractal\Serializer\ArraySerializer());
return response()->json($manager->createData($response)->toArray());
}
public function show($id)
{
$track = Track::find($id);
return $this->respondWithItem($track, new TrackTransformer);
}
}
Run Code Online (Sandbox Code Playgroud)
另外,我在一个特定的控制器上实现它,即使我有这个工作,我在哪里添加代码/类,以便我可以获得所有控制器的ArraySerializer输出?
如果有帮助的话,我已经在Github上发布了这个.
events.js:141
throw er; // Unhandled 'error' event
MongoError: connection 0 to localhost:27017 timed out
at Function.MongoError.create (/home/ubuntu/scripts/node_modules/mongodb-core/lib/error.js:29:11)
at Socket.<anonymous> (/home/ubuntu/scripts/node_modules/mongodb-core/lib/connection/connection.js:184:20)
at Socket.g (events.js:260:16)
at emitNone (events.js:67:13)
at Socket.emit (events.js:166:7)
at Socket._onTimeout (net.js:318:8)
at _runOnTimeout (timers.js:524:11)
at _makeTimerTimeout (timers.js:515:3)
at Timer.unrefTimeout (timers.js:584:5)
Run Code Online (Sandbox Code Playgroud)
好吧,在连接过程中没有错误,但是当尝试保存一些模型/集合时,它会运行一段时间,然后它会抛出此错误.BTW我还有另一个节点进程连接到同一个mongodb服务器.任何帮助都非常感谢.
Chatrooms.findOneAndUpdate({Roomname: room.Roomname},{ $setOnInsert: {status: true, userNum: 1}}, {new: true, upsert: true}, function(err, doc) {
if(err) console.log(err);
console.log("DOC " + doc)
if(doc.status) {
// FOUND ROOM SATTUS IS TRUE LOGIC
console.log(doc);
// return callback(true)
}
});
Run Code Online (Sandbox Code Playgroud)
上面的查询将返回给我更新或插入的实际文档,但我无法确切地检查它是哪一个。如果我进行更新而不是 findOneandUpdate 我会返回这个
{
ok: 1,
nModified: 0,
n: 1,
upserted: [ { index: 0, _id: 55df883dd5c3f7cda6f84c78 } ]
}
Run Code Online (Sandbox Code Playgroud)
如何从写入结果中返回文档和写入结果或至少返回插入的字段。
PHP代码:
<?php
$key = 0;
if($key == 'monty' && $key == 'anil'){
echo 'Mackraja';
}else{
echo "Nothing";
}
?>
Run Code Online (Sandbox Code Playgroud)
要么
<?php
$key = 2;
if($key == '2abc' || $key == 'abc2'){
echo 'Mackraja';
}else{
echo "Nothing";
}
?>
Run Code Online (Sandbox Code Playgroud)
输出:Mackraja
我遇到了新的Linux设置问题 - 我已将nodemon安装为本地依赖项(非全局),我正在尝试从我的package.json"start"-script执行它.我收到此权限错误.
node通过我尝试用自己的伟大工程,但只要babel-node还是nodemon甚至mocha,我得到许可的问题.
我的设置分为两个硬盘驱动器 - 节点安装在我的SSD(我的操作系统)上,我的项目(以及我尝试执行的node_modules nodemon是在我的存储硬盘上.
sh: 1: nodemon: Permission denied
npm ERR! Linux 3.19.0-56-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "start"
npm ERR! node v5.9.0
npm ERR! npm v3.7.3
npm ERR! code ELIFECYCLE
npm ERR! vyggo-easyrtc@1.0.0 start: `nodemon --exec node entry`
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the vyggo-easyrtc@1.0.0 start script 'nodemon --exec node entry'.
npm ERR! Make sure you have the latest version of …Run Code Online (Sandbox Code Playgroud) 我正在使用条纹php库.
这是我的代码:
$account = \Stripe\Account::create(
array(
"country" => "US",
"managed" => true,
"legal_entity" => array(
'address' => array(
'city' => 'Maxico',
'country' => 'US',
"line1" => 'H65',
"line2" => 'standfort street',
"postal_code" => '90046',
"state" => 'CA'
),
'business_name' => 'test business name',
'business_tax_id' => '000000000',
'dob' => array(
'day' => '10',
'month' => '01',
'year' => '1988'
),
'first_name' => 'Test',
'last_name' => 'Tester',
'personal_id_number' => '000000000',
'ssn_last_4' => '0000',
'type' => 'sole_prop'
),
'tos_acceptance' => array(
'date' => …Run Code Online (Sandbox Code Playgroud) 我想在 spring mvc 方法中重定向到另一个 .jsp。我不想使用 javascripts 方法,例如:window.location.replace(url)。
我的方法:
@RequestMapping(value= "loginUser", method=RequestMethod.POST)
public @ResponseBody String loginUser (@RequestParam("name") String name, @RequestParam("password") String password){
return "";
}
Run Code Online (Sandbox Code Playgroud) 我很抱歉,如果这个问题已被问到我确定某处必须有一个答案,但由于某些或其他原因我无法找到它,可能使用错误的搜索查询
我知道您可以使用媒体查询来定位不同的设备,如下所示:
@media only screen and (max-device-width: 480px) {
div#wrapper {
width: 400px;
}
}
Run Code Online (Sandbox Code Playgroud)
但我想知道的是,如何根据所查看的设备更改我的网站设计?
例
让我们说我的正常网站结构是这样的:
如果桌面
<div id="user">
<div id="profilePic">
<img src="images/responSiveTest/ppic.PNG" class="p-img" />
</div>
<div id="uname">
<h4 style="color:white">Welcome Guest</h4>
<p style="color:white">Please Log in</p>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
现在,当用户在移动设备上查看我的网站时,如何更改我的div/网站布局,让我们说一些不同的东西
如果移动设备
<div id="mobileNav">
<div id="namePic">
<!-- Mobile user -->
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
希望我的要求是有道理的,感谢这个神奇的网站上的每个人都提供帮助
我不明白为什么我的反序列化方法被多次调用。这是我的server.js文件
var express = require('express');
var app = express();
var passport = require('passport');
var bodyParser = require('body-parser');
var session = require('express-session');
var MongoSessionStore = require('connect-mongo/es5')(session);
// Local ENV ======================================================================
var env = require('./config/config.json')[app.get('env')];
// Mongo Database ======================================================================
var mongoInstance = require('./config/db.config.js');
mongoInstance.connection.on('open', function(){
console.log('connection works');
});
// Configuration ======================================================================
app.use(session({
secret: 'secretsarenofun', // Change this to anything else
resave: false,
saveUninitialized: true,
store: new MongoSessionStore({
mongooseConnection: mongoInstance.connection,
autoRemoveInterval: 60
})
}));
require('./config/passport.config.js')(passport, env, mongoInstance);
app.use(passport.initialize());
app.use(passport.session());
// Routes ======================================================================
var …Run Code Online (Sandbox Code Playgroud) node.js ×4
php ×3
mongodb ×2
mongoose ×2
passport.js ×2
casting ×1
compare ×1
css ×1
dependencies ×1
html ×1
laravel ×1
linux ×1
mobile ×1
permissions ×1
spring ×1
spring-mvc ×1
string ×1