diff --git a/docker-compose.yml b/docker-compose.yml index d4dfa48..f62e473 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,4 +16,4 @@ services: depends_on: - memcached ports: - - 5000:5000 + - 80:5000 diff --git a/proxy.mjs b/proxy.mjs index 52c6254..0326581 100644 --- a/proxy.mjs +++ b/proxy.mjs @@ -1,11 +1,19 @@ import http from 'http' import httpProxy from 'http-proxy' -const proxy = httpProxy.createProxyServer({}) +function start() { + try { + const proxy = httpProxy.createProxyServer({}) + const server = http.createServer(function (req, res) { + const target = req.url.startsWith('/api/') ? 'http://localhost:5000' : 'http://localhost:3000' + proxy.web(req, res, { target }) + }) + server.listen(1234) -var server = http.createServer(function (req, res) { - const target = req.url.startsWith('/api/') ? 'http://localhost:5000' : 'http://localhost:3000' - proxy.web(req, res, { target }) -}) + server.on('error', () => start()) + } catch (e) { + start() + } +} -server.listen(1234) +start() diff --git a/src/note/model.rs b/src/note/model.rs index 5916536..6cbb092 100644 --- a/src/note/model.rs +++ b/src/note/model.rs @@ -7,7 +7,7 @@ pub struct Note { pub meta: String, pub contents: String, pub views: Option, - pub expiration: Option, + pub expiration: Option, } #[derive(Serialize, Deserialize, Clone)] diff --git a/src/note/routes.rs b/src/note/routes.rs index 7e8fd58..5c1438c 100644 --- a/src/note/routes.rs +++ b/src/note/routes.rs @@ -6,11 +6,11 @@ use crate::note::{generate_id, Note, NoteInfo, NotePublic}; use crate::size::LIMIT; use crate::store; -fn now() -> u64 { +pub fn now() -> u32 { SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .unwrap() - .as_secs() + .as_secs() as u32 } #[derive(Serialize, Deserialize)] @@ -86,10 +86,12 @@ async fn delete(path: web::Path) -> impl Responder { } _ => {} } + + let n = now(); match changed.expiration { Some(e) => { - store::del(&p.id.clone()); - if e < now() { + if e < n { + store::del(&p.id.clone()); return HttpResponse::BadRequest().finish(); } } diff --git a/src/store.rs b/src/store.rs index 681e143..4c09b13 100644 --- a/src/store.rs +++ b/src/store.rs @@ -1,5 +1,6 @@ use memcache; +use crate::note::now; use crate::note::Note; lazy_static! { @@ -12,7 +13,11 @@ lazy_static! { pub fn set(id: &String, note: &Note) { let serialized = serde_json::to_string(¬e.clone()).unwrap(); - CLIENT.set(id, serialized, 0).unwrap(); + let expiration: u32 = match note.expiration { + Some(e) => e - now(), + None => 0, + }; + CLIENT.set(id, serialized, expiration).unwrap(); } pub fn get(id: &String) -> Option {