chore: configure github codespace

This commit is contained in:
Oskar 2022-09-26 19:41:37 +00:00
parent eeec5bb1b7
commit 1b9529223a
6 changed files with 82 additions and 6 deletions

16
.devcontainer/Dockerfile Normal file
View File

@ -0,0 +1,16 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/rust/.devcontainer/base.Dockerfile
# [Choice] Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye
ARG VARIANT="buster"
FROM mcr.microsoft.com/vscode/devcontainers/rust:0-${VARIANT}
USER vscode
RUN rustup install nightly \
&& rustup component add rustfmt --toolchain nightly \
&& rustup component add clippy --toolchain nightly
USER root
# [Optional] Uncomment this section to install additional packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

View File

@ -0,0 +1,52 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/rust
{
"name": "Rust",
"build": {
"dockerfile": "Dockerfile",
"args": {
// Use the VARIANT arg to pick a Debian OS version: buster, bullseye
// Use bullseye when on local on arm64/Apple Silicon.
"VARIANT": "bullseye"
}
},
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"lldb.executable": "/usr/bin/lldb",
// VS Code don't watch files under ./target
"files.watcherExclude": {
"**/target/**": true
},
"rust-analyzer.checkOnSave.command": "clippy"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"vadimcn.vscode-lldb",
"mutantdino.resourcemonitor",
"rust-lang.rust-analyzer",
"tamasfe.even-better-toml",
"serayuzgur.crates"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "rustc --version",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}

6
.gitignore vendored
View File

@ -1,5 +1,4 @@
# Generated by Cargo
# will have compiled files and executables
# Rust output
/target
# Logs files
@ -17,3 +16,6 @@ cert.pem
# IDE configs
.idea
.vscode
# Development storage directory
/storage

View File

@ -28,7 +28,7 @@ Now you can run server using command `./target/release/homedisk`.
```bash
# Generate private key
openssl genrsa -out cert.key 204
openssl genrsa -out cert.key 2048
# Generate certificate
openssl req -new -x509 -key cert.key -out cert.pem -days 365
```

View File

@ -11,4 +11,4 @@ secret = "secret key used to sign tokens" # jsonwebtoken secret string used to s
expires = 24 # token expiration time in hours (default one day)
[storage]
path = "/home/homedisk" # path to directory where user files will be stored
path = "storage" # path to directory where user files will be stored

View File

@ -2,7 +2,7 @@ mod api;
pub mod error;
pub mod utils;
use std::path::PathBuf;
use std::{path::{PathBuf, Path}, process::exit};
use anyhow::anyhow;
use axum::{
@ -18,13 +18,19 @@ use tower_http::{
cors::{AllowOrigin, CorsLayer},
BoxError,
};
use tracing::{debug, info};
use tracing::{debug, info, error};
use crate::{config::Config, database::Database};
pub async fn start_server(config: Config, db: Database) -> anyhow::Result<()> {
let host = format!("{}:{}", config.http.host, config.http.https_port);
// check if tls cert and key file exists
if !Path::new(&config.http.tls_cert).exists() || !Path::new(&config.http.tls_key).exists() {
error!("TLS cert or/and key file not found!");
exit(1);
}
tokio::spawn(redirect_http_to_https(config.clone()));
info!("🚀 Server has launched on https://{host}");