我正在使用firebase托管,我在firebase.json中设置了正确的url重写,如下所示:
"rewrites":
[{
"source": "**",
"destination": "/index.html"
}]
Run Code Online (Sandbox Code Playgroud)
这似乎工作正常,因为所有路由都应该通过index.html.但是,当我在路由中有一个以" - "开头的firebase对象ID时,它会抛出404.所以例如my-cool-app.firebaseapp.com/profiles/-JfZA03uAJI7rpqQg0sG会返回404.但是,如果我删除id中的破折号,那么路径似乎是正确重写.
这可能是什么问题?
如何在firebase规则中检查数组中的值.我想做这样的事情:
root.child('connections/'+auth.uid).child('friends').child(someFriendId).exists()
Run Code Online (Sandbox Code Playgroud)
因此,在当前用户的连接节点下,如果在friends数组中存在someFriendId,则允许访问.'someFriendId'不是friends数组的键,也就是使用firebase push()方法生成的自动ID.
来自Transactions doc,第二段:
这里的意图是客户端增加发送的聊天消息总数(暂时忽略有更好的实现方式).
有哪些标准的"更好的方法"来实现这个?
具体来说,我正在尝试做一些事情,比如检索最近的50条记录.这要求我从列表的末尾开始,所以我需要一种方法来确定最后一条记录是什么.
我看到的选项:
我错过了明显的选择吗?
计算表中的记录显然是一种手动操作,直到你们已经在工作中获得一些漂亮的新功能;)
但是,我甚至坚持使用.on('value',...)手动运行来获取计数:
var table = new Firebase('http://beta.firebase.com/user/tablename');
var count = 0;
table.on('child_added', function(snapshot) {
count++;
// how do I know if this is the last child? i.e. the count is complete?
});
// when is it okay to use count?
Run Code Online (Sandbox Code Playgroud)
我预见到任何类型的分页都会出现同样的问题,我觉得我对此有点束缚.我错过了什么?
这基本上是错误的模式,例如,获取用户在他/她的队列中的消息数量?
如果我将数据插入node/a/0firebase中.
结果将a是一个数组a[0].
同样的方法,如果我在node/a/1第一个数组中设置我的数据将变为null
"a" : [ null, {
"-J-22j_Mb59l0Ws0H9xc" : {
"name" : "chok wee ching"
}
} ]
Run Code Online (Sandbox Code Playgroud)
但是,如果 node/a/2
"a" : {
"2" : {
"-J-25xjEXUqcpsC-5LOE" : {
"name" : "chok wee ching"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的猜测,firebase自动将单个0和1视为一个数组.我怎么能阻止这个?
我遇到了使用电子邮件/密码登录Firebase简单登录的奇怪行为:如果我使用现有用户帐户登录,我可以写入Firebase ref(即$ root/list/$ item).如果没有,我没有按预期的写访问权限(Firebase规则似乎没问题),但是如果客户端已登录,并且我同时从Firebase Forge(Auth页面)删除用户,则连接的客户端仍然可以写入访问权限. Firebase参考!它是设计还是错误?谢谢.
这是规则:
{
"rules": {
".read": true,
"list": {
"$item": {
".write": "auth != null && newData.child('author').val() == auth.id",
".validate": "newData.hasChildren(['author', 'content'])",
"author": {
".validate": "newData.val() == auth.id"
},
"content": {
".validate": "newData.isString()"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 这是数据库模式:
以下是规则:
"notifications": {
"$year": {
".read": "false",
".write": "!data.exists()",
"$month": {
".read": "false",
".write": "!data.exists()",
"$day": {
".read": "false",
".write": "!data.exists()",
"$hour": {
".read": "false",
".write": "!data.exists()",
"$minute": {
".read": "false",
".write": "!data.exists()",
"$data": {
".read": "false",
".write": "!data.exists()"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何验证(使用".validate"或".write"规则)用户只能在该树中输入整数?或者有一些解决方法吗?
我想要实现的是创建只写(没有删除或更新)日志,该日志具有一些结构并将在以后处理.我可以将结构更改为2015-10-6-17-30之类的密钥或其他内容.我简直不敢相信Firebase没有针对这种情况的东西.
更新:这不重复,我正在寻找一种解决方法,或者其他能帮助我实现目标的东西.
在其中一个应用程序中,我正在获取以下消息。 星期一2014年8月18日23:59:59 IST 是angular js的ng-repeat
Offer ends: {{msg.endTime}}
Run Code Online (Sandbox Code Playgroud)
哪个渲染为应用程序以这种格式接收日期。 优惠结束:2014年8月18日星期一23:59:59
我想显示剩余时间而不是日期/时间。点赞优惠在2天40分钟10秒内结束
无需担心TIMEZone即可轻松实现的简单方法
我打算将Moment.js与格式一起使用 moment().format("ddd MMM HH:mm:SS")
我正在使用gulp.watch遇到这个错误.基本上,当测试单元因错误而失败时,watch命令会挂起 - 即只运行一次然后watch再次不会触发事件.
规定的解决方法是使用gulp-plumber来防止错误退出.但是,这仅适用于流.如果我和browserify一起运行业力测试,我的配置看起来与此类似(我无法确定如何将流连接到这个坏男孩以启用管道工):
gulp.task('watch', function() {
gulp.watch('src/**/*.js', ['test']);
gulp.watch('test/**/*.spec.js', ['test']);
});
gulp.task('test', function () {
return karma.server.start({
files: [
'test/**/*.spec.js'
],
frameworks: ['browserify', 'jasmine'],
preprocessors: {
'test/**/*.spec.js': ['coverage', 'browserify']
},
browsers: ['PhantomJS'],
reporters: ['coverage', 'spec', 'failed'],
browserify: {
debug: true,
transform: ['browserify-istanbul']
},
singleRun: true
});
});
Run Code Online (Sandbox Code Playgroud)
有没有人有一个解决方法来运行测试单元与手表或建议如何让这与gulp管道工一起工作?
我正在尝试将一些安全规则应用于我们的 firebase 实例,但我似乎无法从 iOS 接到电话来尊重它们。我从一个简单的测试开始,验证身份验证(应该成功),然后尝试将未定义的值写入根(应该失败)。
规则:
{
"rules":
{
//Default read and write access to authenticated users only
".read" : "auth != null",
".write" : "auth != null",
//Prevent undefined child variables
"$undef" : { ".validate" : false }
}
}
Run Code Online (Sandbox Code Playgroud)
登录:
- (void)authenticate
{
[_dataRef authWithCredential:SECURITY_CREDENTIAL //Firebase Secret JSON token
withCompletionBlock:^(NSError *error, id data){}
withCancelBlock:^(NSError *error)
{
//If the authentication becomes invalid, re-authenticate
[self authenticate];
}];
}
Run Code Online (Sandbox Code Playgroud)
编写测试:
[[[[Firebase alloc] initWithUrl:ROOT_URL] childByAppendingPath:CHILD_PATH] setValue:VALUE];
Run Code Online (Sandbox Code Playgroud)
现在我似乎无法弄清楚为什么模拟器无法正确写入该值,但 iOS 会忽略验证并写入数据。
另外,在进一步测试后,我遇到了由此产生的第二个问题。如果我更改用于身份验证的凭据不是有效的 firebase 秘密令牌,iOS …
我目前正在调查Google Cloud Functions,并使用typescript编写了一些基本的测试函数.
这些函数按预期工作,我现在正尝试使用Jasmine创建单元测试.(我不是按照文档使用Chai/sinon,因为我的项目的其余部分使用了jasmine).
我有两个问题1)由于此错误,测试未运行
抛出新错误('Firebase配置变量不可用.'+ ^错误:Firebase配置变量不可用.请使用最新版本的Firebase CLI来部署此功能
2)鉴于测试确实运行,我不确定如何测试响应是否符合预期.
索引文件
import * as functions from 'firebase-functions'
import { helloWorldHandler } from './functions/hello-world';
export let helloWorld = functions.https.onRequest((req, res) => {
helloWorldHandler(req, res);
});
Run Code Online (Sandbox Code Playgroud)
正在测试的文件
export let helloWorldHandler = (request, response) => {
response.send("Hello from Firebase Cloud!");
}
Run Code Online (Sandbox Code Playgroud)
规格
import {} from 'jasmine';
import * as functions from 'firebase-functions'
import { helloWorldHandler } from './hello-world';
import * as endpoints from '../index';
describe('Cloud Functions : Hello World', () => {
let configStub …Run Code Online (Sandbox Code Playgroud) firebase ×9
angularjs ×2
browserify ×1
date ×1
gulp ×1
gulp-watch ×1
jasmine ×1
javascript ×1
karma-runner ×1
momentjs ×1
typescript ×1
unit-testing ×1