Comments (7)
I want to build a website using gRPC like https://github.com/improbable-eng/grpc-web, but with a Rust backend. I'm pretty sure it works with gRPC and other content on the same port. I don't think it is unreasonable. I'll investigate and find out.
from grpc-rust.
grpc::ServerBuilder
now (in master) exposes http::ServerBuilder
which can be used to attach custom HTTP service implementation.
from grpc-rust.
It should be possible with little development.
But please note that httpbis doesn't support HTTP/1 currently.
from grpc-rust.
It should be possible with little development.
😄
But please note that httpbis doesn't support HTTP/1 currently.
👍 I don't think I need HTTP/1 if those things can be served to Chrome over HTTP/2. It is an internal website where I can have everyone use Chrome.
from grpc-rust.
Hi @stepancheg, thank you for making this change! I tried today to make it work, but am stuck. Here is video and the code that I've been trying.
modified greeter_server.rs
extern crate futures;
extern crate grpc_examples;
extern crate grpc;
extern crate httpbis;
//extern crate tls_api_stub;
extern crate tls_api_openssl;
extern crate tls_api;
use tls_api::TlsAcceptorBuilder as tls_api_TlsAcceptorBuilder;
use std::thread;
use grpc_examples::helloworld_grpc::*;
use grpc_examples::helloworld::*;
use std::sync::Arc;
struct GreeterImpl;
impl Greeter for GreeterImpl {
fn say_hello(&self, _m: grpc::RequestOptions, req: HelloRequest) -> grpc::SingleResponse<HelloReply> {
let mut r = HelloReply::new();
let name = if req.get_name().is_empty() { "world" } else { req.get_name() };
println!("greeting request from {}", name);
r.set_message(format!("Hello {}", name));
grpc::SingleResponse::completed(r)
}
}
struct ServiceB;
impl httpbis::Service for ServiceB {
fn start_request(&self, req_headers: httpbis::Headers, _req: httpbis::HttpPartStream)
-> httpbis::Response
{
let mut resp_headers = httpbis::Headers::ok_200();
resp_headers.add("content-type", "text/plain; charset=utf-8");
httpbis::Response::headers_and_bytes(resp_headers, "service B")
}
}
fn create_http() -> httpbis::ServerBuilder<tls_api_openssl::TlsAcceptor> {
let pkcs12 = include_bytes!("../../../../rust-http2/tests/identity.p12");
let mut tls_acceptor = tls_api_openssl::TlsAcceptorBuilder::from_pkcs12(pkcs12, "mypass")
.expect("acceptor builder");
tls_acceptor.set_alpn_protocols(&[b"h2"]).expect("set_alpn_protocols");
let mut conf = httpbis::ServerConf::new();
conf.alpn = Some(httpbis::ServerAlpn::Require);
let mut server = httpbis::ServerBuilder::new();
server.set_tls(tls_acceptor.build().expect("tls acceptor"));
server.conf = conf;
server.service.set_service("/b", Arc::new(ServiceB{}));
server
}
fn main() {
let http = create_http();
let conf = grpc::ServerConf::new();
let mut server: grpc::ServerBuilder<tls_api_openssl::TlsAcceptor> = grpc::ServerBuilder {http: http, conf: conf };
server.http.set_port(50051);
server.add_service(GreeterServer::new_service_def(GreeterImpl));
server.http.set_cpu_pool_threads(4);
let _server = server.build().expect("server");
loop {
thread::park();
}
}
from grpc-rust.
@stepancheg, can we reopen this until there is a working solution? I was recently laid off and I've got some ideas that I want to explore while I have some free time, but I am blocked until this works.
from grpc-rust.
Serving static content and handling gRPC requests are two very different things. It would be best to simply create a server which uses this lib for gRPC and then rocket, hyper or any other framework to serve static content.
They could exists in the same server. Running in the same container (if that is how you deploy). Same binary. Problem solved.
from grpc-rust.
Related Issues (20)
- Cannot find `grpc::ClientBuilder` in examples
- TLS client credentials exposed on service call implementation
- Generates code with allow(clippy) instead of allow(clippy::all) HOT 4
- Avoid collisions with protobuf fields that are rust keywords
- Generate module definitions
- greeter example gives unhelpful error message HOT 4
- protoc-rust-grpc dependency on protoc-rust is too loose
- Unclear how to send an empty response stream
- Compilation issue on windows for 0.8.0 version HOT 1
- how to authority?
- ServerResponseUnarySink sent GrpcStatus error code but client failed to recognize HOT 1
- Canceling a streaming call from client side HOT 2
- Build fails on Latest Commit HOT 4
- Example code in Readme.md may be out of date.
- build error HOT 4
- grpc- servive Stuck HOT 1
- TLS client panic!
- Add #[derive(Clone)] to Client HOT 2
- Q: is it possible to use grpc-rust with C based Protocol Buffers? HOT 1
- (Duplicate) What's the development status of this project? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grpc-rust.