rewrite backend in rust #32

Merged
lbailly merged 14 commits from rewrite into master 2024-06-13 13:20:05 +02:00
4 changed files with 65 additions and 4 deletions
Showing only changes of commit 217a273f0b - Show all commits

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
.envrc .envrc
.direnv .direnv
/nixos.qcow2
# Added by cargo # Added by cargo

62
nix/vm.nix Normal file
View file

@ -0,0 +1,62 @@
{ pkgs, lib, ... }:
{
nix = {
nixPath = [
"nixpkgs=${builtins.storePath pkgs.path}"
"nixos=${builtins.storePath pkgs.path}"
];
package = pkgs.lix;
};
environment.systemPackages = with pkgs; [ wget tmux ];
services.nginx = {
enable = true;
virtualHosts."localhost" = {
default = true;
locations = {
"/" = {
root = "/traque/static";
tryFiles = "$uri @backend";
};
"@backend" = {
recommendedProxySettings = true;
proxyPass = "http://localhost:8000";
extraConfig = ''
proxy_set_header Connection ''';
proxy_http_version 1.1;
chunked_transfer_encoding off;
proxy_buffering off;
proxy_cache off;
'';
};
};
#extraConfig = ''
# error_page 502 =503;
#'';
};
};
services.getty = {
autologinUser = "root";
helpLine = lib.mkForce ''
On serial console: type Ctrl-a c to switch to the qemu console and `quit` to stop the VM.
traque source is on /traque (rw), `cd /traque && ./target/debug/traque` to run the test.
Compile from the host for performance (the VM is highly limited).'';
};
nixos-shell.mounts = {
mountHome = false;
mountNixProfile = false;
cache = "none";
extraMounts = {
"/traque" = {
target = toString ../.;
cache = "none";
};
};
};
virtualisation = {
forwardPorts = [
{ from = "host"; host.port = 8000; guest.port = 80; }
];
};
system.stateVersion = "24.11";
}

View file

@ -1,4 +1,4 @@
{ pkgs ? (import <nixpkgs>) { }, lib ? pkgs.lib}: { pkgs ? (import <nixpkgs>) { }, lib ? pkgs.lib}:
pkgs.mkShell { pkgs.mkShell {
buildInputs = with pkgs; [ cargo rustc rustfmt ]; buildInputs = with pkgs; [ cargo rustc rustfmt nixos-shell ];
} }

View file

@ -1,7 +1,6 @@
#[macro_use] #[macro_use]
extern crate rocket; extern crate rocket;
use rocket::{ use rocket::{
fs::{relative, FileServer},
response::stream::Event, response::stream::Event,
tokio::{ tokio::{
self, select, self, select,
@ -102,8 +101,7 @@ async fn rocket() -> _ {
.manage(key) .manage(key)
.mount("/", routes![index]) .mount("/", routes![index])
.mount("/track", track::routes()) .mount("/track", track::routes())
.mount("/admin", admin::routes()) .mount("/admin", admin::routes());
.mount("/", FileServer::from(relative!("static")));
tokio::spawn(async move { tokio::spawn(async move {
let mut clean_interval = time::interval(5 * EVENT_TIMEOUT); let mut clean_interval = time::interval(5 * EVENT_TIMEOUT);
let mut coord_interval = time::interval(Duration::from_millis(3000)); let mut coord_interval = time::interval(Duration::from_millis(3000));