-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wait until add extra to sea-query [PR](SeaQL/sea-query#611) Wait until fix cors to tonic_web [PR](hyperium/tonic#1286)
- Loading branch information
Showing
17 changed files
with
121 additions
and
39 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VITE_GRPCSERVER_BIND_URI=[::1]:50053 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { GrpcWebFetchTransport } from "@protobuf-ts/grpcweb-transport"; | ||
|
||
console.log(import.meta.env); | ||
|
||
export const baseUrl = import.meta.env.VITE_GRPCSERVER_BIND_URI; | ||
|
||
export const GrpcTransport = new GrpcWebFetchTransport({ | ||
baseUrl: "http://" + baseUrl, | ||
format: "binary" | ||
}); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
import { fileURLToPath, URL } from 'node:url' | ||
|
||
import { defineConfig } from 'vite' | ||
import { defineConfig, loadEnv } from 'vite' | ||
import vue from '@vitejs/plugin-vue' | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [vue()], | ||
resolve: { | ||
alias: { | ||
'@': fileURLToPath(new URL('./src', import.meta.url)) | ||
export default defineConfig(({ command, mode }) => { | ||
const env = loadEnv(mode, process.cwd(), ''); | ||
process.env = {...process.env, ...env}; | ||
return { | ||
plugins: [vue()], | ||
resolve: { | ||
alias: { | ||
'@': fileURLToPath(new URL('./src', import.meta.url)), | ||
}, | ||
define: { | ||
// __APP_ENV__: env.APP_ENV, | ||
}, | ||
} | ||
} | ||
}) |
Empty file.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE EXTENSION IF NOT EXISTS citus; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
syntax = "proto3"; | ||
package index; | ||
// import "google/protobuf/timestamp.proto"; | ||
|
||
message Index{ | ||
string id = 1; | ||
|
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,44 @@ | ||
use super::RequestResult; | ||
use crate::model::log_index as LogIndex; | ||
use sea_orm::{DatabaseConnection, EntityTrait}; | ||
use tonic::{Response, Status}; | ||
|
||
mod admin; | ||
mod index; | ||
mod index; | ||
|
||
pub use admin::admin_panel_server::AdminPanelServer; | ||
|
||
pub struct AdminRpcServer { | ||
pub db: DatabaseConnection, | ||
} | ||
|
||
#[tonic::async_trait] | ||
impl admin::admin_panel_server::AdminPanel for AdminRpcServer { | ||
/// | ||
async fn get_indexes( | ||
&self, | ||
request: tonic::Request<index::IndexListRequest>, | ||
) -> RequestResult<index::IndexListResponse> { | ||
match LogIndex::Entity::find().all(&self.db).await { | ||
Ok(data) => Ok(Response::new(index::IndexListResponse { | ||
indexes: data | ||
.into_iter() | ||
.map(|m| index::Index { | ||
id: m.id.to_string(), | ||
name: m.name.unwrap_or_default(), | ||
}) | ||
.collect(), | ||
})), | ||
Err(e) => Err(Status::internal(format!("Database error: {}", e))), | ||
} | ||
} | ||
/// | ||
async fn search( | ||
&self, | ||
request: tonic::Request<index::IndexSearchRequest>, | ||
) -> RequestResult<index::IndexSearchResult> { | ||
Ok(Response::new(index::IndexSearchResult { | ||
response: Vec::new(), | ||
})) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,56 @@ | ||
use sea_orm::DatabaseConnection; | ||
use tonic::{Request, Response, Status, transport::Server}; | ||
use tonic::{transport::Server, Request, Response, Status}; | ||
|
||
mod rpc; | ||
mod admin; | ||
mod rpc; | ||
|
||
use crate::{core, credentials}; | ||
|
||
pub struct RpcServer{ | ||
pub struct RpcServer { | ||
db: DatabaseConnection, | ||
} | ||
|
||
type RequestResult<T> = Result<Response<T>, Status>; | ||
|
||
#[tonic::async_trait] | ||
impl rpc::saver_server::Saver for RpcServer{ | ||
async fn send_message(&self, request: Request<rpc::Message>)->RequestResult<rpc::ResultMessage>{ | ||
impl rpc::saver_server::Saver for RpcServer { | ||
async fn send_message( | ||
&self, | ||
request: Request<rpc::Message>, | ||
) -> RequestResult<rpc::ResultMessage> { | ||
let m = request.get_ref(); | ||
log::info!("rpc request: {:?}", m); | ||
let v = if let Ok(v) = serde_json::from_str(m.data.as_str()) { | ||
v | ||
} else{ | ||
return Err(Status::invalid_argument("Can`t convert json from data")) | ||
} else { | ||
return Err(Status::invalid_argument("Can`t convert json from data")); | ||
}; | ||
if let Err(e) = core::insert_message(&self.db, &m.index, v).await{ | ||
if let Err(e) = core::insert_message(&self.db, &m.index, v).await { | ||
log::error!("Can`t inser value: {}", e); | ||
return Err(Status::internal("Can`t insert value")); | ||
}; | ||
Ok(Response::new(rpc::ResultMessage{ | ||
ok: true | ||
})) | ||
Ok(Response::new(rpc::ResultMessage { ok: true })) | ||
} | ||
} | ||
|
||
pub async fn run(db: DatabaseConnection){ | ||
pub async fn run(db: DatabaseConnection) { | ||
log::info!("Rpc server starting"); | ||
let addr = credentials::grpcserver_bind_uri().parse().unwrap(); | ||
let server = RpcServer{ | ||
db | ||
}; | ||
let server = RpcServer { db: db.clone() }; | ||
let admin = admin::AdminRpcServer { db: db.clone() }; | ||
|
||
let svc = rpc::saver_server::SaverServer::new(server); | ||
|
||
Server::builder().trace_fn(|_|{ | ||
tracing::info_span!("Grpc request: ") | ||
}).add_service(svc).serve(addr).await.unwrap(); | ||
} | ||
let admin_server = admin::AdminPanelServer::new(admin); | ||
let corsed = tonic_web::GrpcWebLayer::new(); | ||
|
||
|
||
Server::builder() | ||
.trace_fn(|_| tracing::info_span!("Grpc request: {}")) | ||
.accept_http1(true) | ||
.layer(corsed) | ||
.add_service(admin_server) | ||
.add_service(svc) | ||
.serve(addr) | ||
.await | ||
.unwrap(); | ||
} |