我试图在finagle中托管静态资源,如javascript和css文件.
我已经设法让它工作,但我必须专门配置我的路由服务中的资源文件夹的每个路由.例如:
def build():RoutingService[Request with Request] = {
val routingService = RoutingService.byPathObject {
case Root => ControllerRegistry.rootController.root()
case Root / "public" / resource => ControllerRegistry.publicController.findPublic()
case Root / "public" / "bootstrap"/ "css" / resource => ControllerRegistry.publicController.findPublic()
}
routingService
}
Run Code Online (Sandbox Code Playgroud)
和
def findPublic(): Service[Request, Response] = {
val findPublic = new Service[Request, Response] {
def apply(request: Request) = {
Future {
val resource = Path(request.path) match {
case Root / "public" / resource => getResourceText(s"/public/$resource")
case Root / "public" / "bootstrap" …Run Code Online (Sandbox Code Playgroud) 我有一个单独的服务来管理文件和 s3 身份验证。它生成预签名的 URL,我可以在其他服务中使用它来上传(和下载)文件。
我想利用Multipart upload sdk - 目前'uploadToUrl'方法似乎将大部分时间花在getResponseCode上,因此很难提供用户反馈。另外,在我的测试中,分段上传似乎要快得多。
理想情况下,我希望能够使用预签名 URL 而不是临时使用的密钥/访问密钥来创建一些 AWSCredentials。这只是一个白日梦吗?
//s3 service
public URL getUrl(String bucketName, String objectKey, Date expiration, AmazonS3 s3Client, HttpMethod method, String contentType) {
GeneratePresignedUrlRequest generatePresignedUrlRequest;
generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, objectKey);
generatePresignedUrlRequest.setMethod(method);
generatePresignedUrlRequest.setExpiration(expiration);
generatePresignedUrlRequest.setContentType(contentType);
URL s = s3Client.generatePresignedUrl(generatePresignedUrlRequest);
System.out.println(String.format("Generated Presigned URL: %n %S", s.toString()));
return s;
}
//Upload service
Override
public void uploadToUrl(URL url, File file) {
HttpURLConnection connection;
try {
InputStream inputStream = new FileInputStream(file);
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("PUT");
OutputStream out …Run Code Online (Sandbox Code Playgroud) 如果没有复制和粘贴大量代码,这可能很难描述,但我会尝试.
我不得不使用javascript构建一个自定义可拖动对象 - 我过去使用过jquery但它不能用于这个项目.我得到它主要是工作,除了当用户点击对象(一个DIV)并将其拖过页面时,他或她的光标变为经典的工字梁文本选择器.
无论我尝试什么,我都无法禁用此光标.我尝试过像这样的东西.
this.style.cursor = 'pointer';
Run Code Online (Sandbox Code Playgroud)
在div的'onmousedown'函数中,但是一旦你开始拖动blammo,你就有了一个i-beam光标.如果我将上面的代码放在实际的拖动函数中也是如此.
我已经尝试使用css禁用整个文档中的文本选择(不是实际的解决方案,因为我希望人们能够在此站点上复制/粘贴,但只是为了查看它是否有效)仍然,光标会在用户拖动.
我想我真正想要的是暂时禁用i-beam光标出现在我的页面上的方法.
好的,提前感谢任何帮助.
在sequlize docs的代码示例中:
if (!!err) {
console.log('Unable to connect to the database:', err)
} else {
console.log('Connection has been established successfully.')
}
Run Code Online (Sandbox Code Playgroud)
他们为什么要(!!err)用来测试那个错误的真实性?是不是一样的if (err)?