minor fixes, add nginx conf

This commit is contained in:
Aiden McClelland
2021-08-05 16:50:12 -06:00
parent 8eaf8f47e4
commit 0ee8361430
4 changed files with 135 additions and 27 deletions

104
appmgr/nginx.conf Normal file
View File

@@ -0,0 +1,104 @@
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
proxy_request_buffering off;
location /rpc {
proxy_pass http://localhost:5959/;
}
location /ws/ {
proxy_pass http://localhost:5960/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}

View File

@@ -11,7 +11,7 @@ use rpc_toolkit::command;
use rpc_toolkit::hyper::upgrade::Upgraded;
use rpc_toolkit::hyper::{Body, Error as HyperError, Request, Response};
use rpc_toolkit::yajrc::RpcError;
use serde::Serialize;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use tokio::task::JoinError;
use tokio_tungstenite::tungstenite::Message;
@@ -19,7 +19,8 @@ use tokio_tungstenite::WebSocketStream;
pub use self::model::DatabaseModel;
use self::util::WithRevision;
use crate::context::RpcContext;
use crate::context::{EitherContext, RpcContext};
use crate::util::{display_serializable, IoFormat};
use crate::{Error, ResultExt};
async fn ws_handler<
@@ -67,24 +68,28 @@ pub async fn subscribe(ctx: RpcContext, req: Request<Body>) -> Result<Response<B
Ok(res)
}
#[command(subcommands(revisions, dump, put, patch))]
pub fn db(#[context] ctx: RpcContext) -> Result<RpcContext, RpcError> {
#[command(subcommands(revisions, dump, put))]
pub fn db(#[context] ctx: EitherContext) -> Result<EitherContext, RpcError> {
Ok(ctx)
}
#[derive(Serialize)]
#[derive(Deserialize, Serialize)]
#[serde(untagged)]
pub enum RevisionsRes {
Revisions(Vec<Arc<Revision>>),
Dump(Dump),
}
#[command(rpc_only)]
#[command(display(display_serializable))]
pub async fn revisions(
#[context] ctx: RpcContext,
#[context] ctx: EitherContext,
#[arg] since: u64,
#[allow(unused_variables)]
#[arg(long = "format")]
format: Option<IoFormat>,
) -> Result<RevisionsRes, RpcError> {
let cache = ctx.revision_cache.read().await;
let rpc_ctx = ctx.as_rpc().unwrap();
let cache = rpc_ctx.revision_cache.read().await;
if cache
.front()
.map(|rev| rev.id <= since + 1)
@@ -99,40 +104,37 @@ pub async fn revisions(
))
} else {
drop(cache);
Ok(RevisionsRes::Dump(ctx.db.dump().await))
Ok(RevisionsRes::Dump(rpc_ctx.db.dump().await))
}
}
#[command(rpc_only)]
pub async fn dump(#[context] ctx: RpcContext) -> Result<Dump, RpcError> {
Ok(ctx.db.dump().await)
#[command(display(display_serializable))]
pub async fn dump(
#[context] ctx: EitherContext,
#[allow(unused_variables)]
#[arg(long = "format")]
format: Option<IoFormat>,
) -> Result<Dump, RpcError> {
Ok(ctx.as_rpc().unwrap().db.dump().await)
}
#[command(subcommands(ui))]
pub fn put(#[context] ctx: RpcContext) -> Result<RpcContext, RpcError> {
pub fn put(#[context] ctx: EitherContext) -> Result<EitherContext, RpcError> {
Ok(ctx)
}
#[command(rpc_only)]
#[command(display(display_serializable))]
pub async fn ui(
#[context] ctx: RpcContext,
#[context] ctx: EitherContext,
#[arg] pointer: JsonPointer,
#[arg] value: Value,
#[allow(unused_variables)]
#[arg(long = "format")]
format: Option<IoFormat>,
) -> Result<WithRevision<()>, RpcError> {
let ptr = "/ui".parse::<JsonPointer>()? + &pointer;
Ok(WithRevision {
response: (),
revision: ctx.db.put(&ptr, &value, None).await?,
})
}
#[command(rpc_only)]
pub async fn patch(
#[context] ctx: RpcContext,
#[arg] patch: DiffPatch,
) -> Result<WithRevision<()>, RpcError> {
Ok(WithRevision {
response: (),
revision: ctx.db.apply(patch, None, None).await?,
revision: ctx.as_rpc().unwrap().db.put(&ptr, &value, None).await?,
})
}

View File

@@ -62,6 +62,7 @@ pub fn echo(#[context] _ctx: EitherContext, #[arg] message: String) -> Result<St
inspect::inspect,
package,
auth::auth,
db::db,
))]
pub fn main_api(#[context] ctx: EitherContext) -> Result<EitherContext, RpcError> {
Ok(ctx)

View File

@@ -193,6 +193,7 @@ pub async fn check_all(ctx: &RpcContext) -> Result<(), Error> {
}
#[derive(Clone, Debug, Deserialize, Serialize, HasModel)]
#[serde(rename_all = "kebab-case")]
pub struct Status {
pub configured: bool,
pub main: MainStatus,