有什么建议吗? Express req.session在另一条路线中是空的。
可以按以下路线打印:
console.log(user)
req.session.userid = user.userid
req.session.username = user.username
c onsole.log('sesesese')
console.log(req.session)
console.log(req.session.userid)
console.log('Is matched!')
res.send({status: 1,userid: req.session.userid})
console.log(req.session)
console.log(req.session.userid)
Session {
cookie:
{ path: '/',
_expires: null,
originalMaxAge: null,
httpOnly: true } }
但是当我使用另一条路线时,req.session是空的:
router.get('/logStatus',function(req, res) {
console.log(req.session.cookie)
console.log(req.session.username)
if (req.session) {
res.send( {userid: req.session.userid,username: req.session.username} )
} else {
res.send({status: 0})
}})
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(cookieParser())
app.use(session({
secret: 'sessionsecret',
resave: false,
saveUninitialized: true,
cookie:{ path: '/', httpOnly: true, secure: false, maxAge: null }
}))
app.use('/',index)
app.use('/admin',admin)
app.use('/test',test)
这是我的app.js:
//get system albums
PHImageRequestOptions * options = [[PHImageRequestOptions alloc] init];
options.networkAccessAllowed = YES;
options.synchronous = YES;
KVPhotoAlbum * userAlum = nil;
PHCachingImageManager * manager = [[PHCachingImageManager alloc] init];
PHFetchResult * systemAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
for (id object in systemAlbums) {
if ([object isKindOfClass:[PHAssetCollection class]]) {
PHAssetCollection * collection = (PHAssetCollection*)object;
if (collection.assetCollectionSubtype == PHAssetCollectionSubtypeSmartAlbumVideos) {
continue;
}
//get photo
PHFetchResult * imageResults = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
if (imageResults.count) {
KVPhotoAlbum * album = [[KVPhotoAlbum alloc] init];
album.collection = collection;
album.title = [collection valueForKey:@"localizedTitle"];
album.photoCount = imageResults.count;
if (collection.assetCollectionSubtype == PHAssetCollectionSubtypeSmartAlbumUserLibrary) {
//camera
userAlum = album;
}else {
[_albums addObject:album];
}
PHAsset * asset = [imageResults lastObject];
[manager requestImageForAsset:asset targetSize:CGSizeMake(60, 60) contentMode:PHImageContentModeDefault options:options resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
album.image = result;
}];
}
}
}
//get albums created by user
PHFetchResult * customAlbums = [PHCollectionList fetchTopLevelUserCollectionsWithOptions:nil];
for (id object in customAlbums) {
if ([object isKindOfClass:[PHAssetCollection class]]) {
PHAssetCollection * collection = (PHAssetCollection*)object;
if (collection.assetCollectionSubtype == PHAssetCollectionSubtypeSmartAlbumVideos) {
continue;
}
//get photo
PHFetchResult * imageResults = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
if (imageResults.count) {
KVPhotoAlbum * album = [[KVPhotoAlbum alloc] init];
album.collection = collection;
album.title = [collection valueForKey:@"localizedTitle"];
album.photoCount = imageResults.count;
[_albums addObject:album];
PHAsset * asset = [imageResults lastObject];
[manager requestImageForAsset:asset targetSize:CGSizeMake(60, 60) contentMode:PHImageContentModeDefault options:options resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
album.image = result;
}];
}
}
}
我已将它存储在mongoDB中,我使用react和fetch,当我获取时,mongo会话存储将添加会话,它们是否隐藏了原始会话?