Skip to content

Commit

Permalink
added nginx conf and wss address to client which now works when deployed
Browse files Browse the repository at this point in the history
  • Loading branch information
SnowdenWintermute committed Jan 23, 2024
1 parent f76b0f2 commit b704746
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
6 changes: 3 additions & 3 deletions client/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

<base href="/">

<link rel="preload" href="/roguelike-racing-client-30dd924dff8a64ed_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
<link rel="modulepreload" href="/roguelike-racing-client-30dd924dff8a64ed.js"></head>
<link rel="preload" href="/roguelike-racing-client-715bddf21eeeb498_bg.wasm" as="fetch" type="application/wasm" crossorigin="">
<link rel="modulepreload" href="/roguelike-racing-client-715bddf21eeeb498.js"></head>
<body>

<script type="module">import init from '/roguelike-racing-client-30dd924dff8a64ed.js';init('/roguelike-racing-client-30dd924dff8a64ed_bg.wasm');</script><script>(function () {
<script type="module">import init from '/roguelike-racing-client-715bddf21eeeb498.js';init('/roguelike-racing-client-715bddf21eeeb498_bg.wasm');</script><script>(function () {
var protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
var url = protocol + '//' + window.location.host + '/_trunk/ws';
var poll_interval = 5000;
Expand Down
6 changes: 3 additions & 3 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ pub fn app() -> Html {
let in_production = std::env!("TRUNK_PROD");
log!(format!("in production: {in_production}"));
let websocket_server_url = if in_production == "true" {
"ws://roguelikeracing.com/ws"
"wss://roguelikeracing.com/ws"
} else {
"ws://127.0.0.1:8082/ws"
// "127.0.0.1:8082/ws"
// "wss://roguelikeracing.com/ws"
"127.0.0.1:8082/ws"
};

html! {
Expand Down
1 change: 1 addition & 0 deletions dockerfiles/server.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ WORKDIR /app
COPY --from=builder /app/server/target .
RUN ls -a
WORKDIR /
EXPOSE 8082
CMD ["./app/release/server"]
28 changes: 28 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
server {
server_name roguelikeracing.com www.roguelikeracing.com;
# if you want to host the static index.html etc:
# root /var/www/roguelike-racing;

# make sure docker-compose is running a container
# which is serving the client on this port
location / {
proxy_pass http://localhost:3001;
proxy_set_header X-Forwarded-For $remote_addr;
}

# connect on client by address: wss://roguelikeracing.com/ws
location /ws {
proxy_pass http://localhost:8082;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}

# displays a test message from the actix server
location /test {
proxy_pass http://localhost:8082;
proxy_set_header X-Forwarded-For $remote_addr;
}

# ... certbot stuff goes here
}
9 changes: 4 additions & 5 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ async fn game_server_route(
}

/// Displays state
async fn get_count(count: web::Data<AtomicUsize>) -> impl Responder {
let current_count = count.load(Ordering::SeqCst);
format!("Visitors: {current_count}")
async fn test_the_server() -> impl Responder {
format!("reached the game server")
}

#[actix_web::main]
Expand All @@ -58,12 +57,12 @@ async fn main() -> std::io::Result<()> {
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(game_server_actor_address.clone()))
.route("/count", web::get().to(get_count))
.route("/test", web::get().to(test_the_server))
.route("/ws", web::get().to(game_server_route))
.wrap(Logger::default())
})
.workers(1)
.bind(("127.0.0.1", 8082))?
.bind(("0.0.0.0", 8082))?
.run()
.await
}

0 comments on commit b704746

Please sign in to comment.