-# preview
-
-[](https://hex.pm/packages/preview)
-[](https://hexdocs.pm/preview/)
-
-```sh
-gleam add preview@1
-```
-```gleam
-import preview
-
-pub fn main() -> Nil {
- // TODO: An example of the project in use
-}
-```
-
-Further documentation can be found at <https://hexdocs.pm/preview>.
+# file server!
## Development
-name = "preview"
+name = "filestuffs"
version = "1.0.0"
# Fill out these fields if you intend to generate HTML documentation or publish
--- /dev/null
+import argv
+import gleam/erlang/process
+import gleam/io
+import mist
+import router
+import wisp
+import wisp/wisp_mist
+
+pub fn main() -> Nil {
+ let args: List(String) = argv.load().arguments
+ case args {
+ ["greet", name] -> io.println("hello " <> name <> "!")
+ ["web", file_path, "-p", password] -> web(file_path, password)
+ _ -> io.println("bad args")
+ }
+
+ Nil
+}
+
+pub fn wassup() -> Int {
+ 42
+}
+
+fn web(file_path: String, password: String) -> Nil {
+ wisp.configure_logger()
+
+ let secret_key_base = wisp.random_string(64)
+
+ let assert Ok(_) =
+ router.handle_request(_, file_path, password)
+ |> wisp_mist.handler(secret_key_base)
+ |> mist.new
+ |> mist.port(8000)
+ |> mist.start
+
+ process.sleep_forever()
+}
+++ /dev/null
-import argv
-import gleam/erlang/process
-import gleam/io
-import mist
-import router
-import wisp
-import wisp/wisp_mist
-
-pub fn main() -> Nil {
- let args: List(String) = argv.load().arguments
- case args {
- ["greet", name] -> io.println("hello " <> name <> "!")
- ["web", file_path] -> web(file_path)
- _ -> io.println("bad args")
- }
-
- // wisp.configure_logger()
-
- Nil
-}
-
-pub fn wassup() -> Int {
- 42
-}
-
-fn web(file_path: String) -> Nil {
- wisp.configure_logger()
-
- let secret_key_base = wisp.random_string(64)
-
- let assert Ok(_) =
- router.handle_request(_, file_path)
- |> wisp_mist.handler(secret_key_base)
- |> mist.new
- |> mist.port(8000)
- |> mist.start
-
- process.sleep_forever()
-}
import simplifile
import wisp
-pub fn handle_request(req: wisp.Request, file_path: String) -> wisp.Response {
+pub fn handle_request(
+ req: wisp.Request,
+ file_path: String,
+ password: String,
+) -> wisp.Response {
use req <- middleware(req)
// use <- wisp.serve_static(req, "/files", file_path)
use <- wisp.serve_static(req, "/styles.css", "./static/styles.css")
wisp.ok()
}
- "/new/" <> _path -> upload(req)
+ "/new/" <> _path -> upload(req, password)
"/files/" <> path -> files(req, "/" <> path, file_path)
_ -> wisp.not_found()
}
wisp.ok()
}
-const password = "greg"
-
-pub fn upload(req: wisp.Request) -> wisp.Response {
+pub fn upload(req: wisp.Request, password: String) -> wisp.Response {
use form <- wisp.require_form(req)
//early return if incorrect password
--- /dev/null
+import filestuffs
+import gleeunit
+
+pub fn main() -> Nil {
+ gleeunit.main()
+}
+
+// gleeunit test functions end in `_test`
+pub fn hello_world_test() {
+ let name = "Joe"
+ let greeting = "Hello, " <> name <> "!"
+
+ assert greeting == "Hello, Joe!"
+}
+
+pub fn wassup_test() {
+ assert filestuffs.wassup() == 42
+}
+++ /dev/null
-import gleeunit
-import preview
-
-pub fn main() -> Nil {
- gleeunit.main()
-}
-
-// gleeunit test functions end in `_test`
-pub fn hello_world_test() {
- let name = "Joe"
- let greeting = "Hello, " <> name <> "!"
-
- assert greeting == "Hello, Joe!"
-}
-
-pub fn wassup_test() {
- assert preview.wassup() == 42
-}