Last active
April 5, 2019 10:53
-
-
Save alexcpn/1e39dd58efbf9ced17805c2f5aa07c6a to your computer and use it in GitHub Desktop.
GRPC- Web JS client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<link rel="shortcut icon" href="#" /> | |
<title>Echo Example</title> | |
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script> | |
<script type="text/javascript" src="compiled.js"></script> | |
<script type="text/javascript"> | |
const module = {}; | |
</script> | |
<script type="text/javascript"> | |
var SomeServiceClient = xxx.yyy_service.SomeServiceClient; | |
var client = new SomeServiceClient('http://localhost:8080', null, null); | |
var parameters = new xxx.yyy_service.Parameters(); | |
var response = new xxx.yyy_service.Response(); | |
var fileDetails = new xxx.yyy_serviceFileDetails(); | |
$(document).ready(function () { | |
console.log("document loaded"); | |
fileDetails.setFileurl("some string") | |
parameters.setFileDetails(fileDetails) | |
status = client.testme(parameters, {},function (err, response) { | |
console.log('testme response: ' + response); | |
}); | |
// for server side streaming - do somethig like below -- not tested this for this porto | |
// but tested for the ones I use | |
var stream = client.testMeRealTime(parameters, {}); | |
stream.on('data', function (response) { | |
var stream_output =response.response ; //change it to whatever is the message data | |
console.log(stream_output); | |
}); | |
stream.on('status', function (status) { | |
if (status.code != grpc.web.StatusCode.OK) { | |
console.log('Error code: ' + status.code + ' "' + status.details + '"'); | |
} | |
if (status.metadata) { | |
console.log("Received metadata"); | |
console.log(status.metadata); | |
} | |
}); | |
stream.on('end', function () { | |
console.log("stream end signal received"); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<div class="container"> | |
<p class="help-block">Some Test</p> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
master_process off; | |
worker_processes 1; | |
pid nginx.pid; | |
error_log stderr debug; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
access_log off; | |
client_max_body_size 0; | |
client_body_temp_path client_body_temp; | |
proxy_temp_path proxy_temp; | |
proxy_request_buffering off; | |
server { | |
listen 5000; | |
server_name localhost; | |
index index.html; | |
root /usr/share/nginx/html; | |
location / { | |
if ($request_method = 'OPTIONS') { | |
add_header 'Access-Control-Allow-Origin' '*'; | |
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | |
# | |
# Custom headers and headers various browsers *should* be OK with but aren't | |
# | |
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; | |
# | |
# Tell client that this pre-flight info is valid for 20 days | |
# | |
add_header 'Access-Control-Max-Age' 1728000; | |
add_header 'Content-Type' 'text/plain; charset=utf-8'; | |
add_header 'Content-Length' 0; | |
return 204; | |
} | |
if ($request_method = 'POST') { | |
add_header 'Access-Control-Allow-Origin' '*'; | |
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | |
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; | |
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; | |
} | |
if ($request_method = 'GET') { | |
add_header 'Access-Control-Allow-Origin' '*'; | |
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; | |
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; | |
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment