port forwarding is working

This commit is contained in:
Azizul Karim 2025-01-31 00:51:11 +06:00
parent 0829e0f03f
commit 7fadc22ce0
No known key found for this signature in database
GPG key ID: EC7B9BE87276BA4B
2 changed files with 90 additions and 56 deletions

View file

@ -23,9 +23,14 @@ serve:
ifeq ($(DEBUG),1) ifeq ($(DEBUG),1)
elm-go src/Main.elm \ elm-go src/Main.elm \
--dir=../public \ --dir=../public \
--start-page=index.html \ --port=8000 \
--start-page=../public/index.html \
--host=localhost \ --host=localhost \
-- --debug --proxy-prefix=/ \
--proxy-host=http://localhost:8080 \
-- \
--debug \
--output=../public/elm.min.js
else ifeq ($(RELEASE),1) else ifeq ($(RELEASE),1)
$(error Cannot use serve target with RELEASE=1) $(error Cannot use serve target with RELEASE=1)
endif endif

View file

@ -1,28 +1,30 @@
module Page.Landing exposing module Page.Landing exposing
( Model ( Model
, Msg , Msg
, view
, init , init
, update
, subscriptions , subscriptions
, update
, view
) )
import Element exposing (Element) import Element exposing (Element)
import Websockets import Element.Background
import Ports import Element.Input
import EncodeDecode
import Html.Attributes exposing (placeholder)
import Json.Decode as Decode import Json.Decode as Decode
import Json.Encode as Encode exposing (Value) import Json.Encode as Encode exposing (Value)
import Html.Attributes exposing (placeholder) import Ports
import Element.Input import Websockets
import Element.Background
import EncodeDecode
type alias Model = { type alias Model =
time : String, { time : String
greetWidgetText : String, , greetWidgetText : String
greeting : String , greeting : String
} }
type Msg type Msg
= DownMsg EncodeDecode.DownMsg = DownMsg EncodeDecode.DownMsg
| UpMsg EncodeDecode.LandingUpMsg | UpMsg EncodeDecode.LandingUpMsg
@ -30,15 +32,17 @@ type Msg
| GreetWidgetText String | GreetWidgetText String
| NoOp | NoOp
init : () -> ( Model, Cmd Msg ) init : () -> ( Model, Cmd Msg )
init flags = ( init flags =
{ time = "time not yet set" ( { time = "time not yet set"
, greetWidgetText = "" , greetWidgetText = ""
, greeting = "" , greeting = ""
}, }
Cmd.none , Cmd.none
) )
subscriptions : Model -> Sub Msg subscriptions : Model -> Sub Msg
subscriptions model = subscriptions model =
Ports.socketOnEvent Ports.socketOnEvent
@ -48,34 +52,50 @@ subscriptions model =
(\_ -> NoOp) (\_ -> NoOp)
(\message -> (\message ->
case Decode.decodeString EncodeDecode.downMsgDecoder message.data of case Decode.decodeString EncodeDecode.downMsgDecoder message.data of
Ok msg -> DownMsg msg Ok msg ->
Err err -> DecodeError err DownMsg msg
Err err ->
DecodeError err
) )
(\_ -> NoOp) (\_ -> NoOp)
) )
update : Msg -> Model -> ( Model, Cmd Msg ) update : Msg -> Model -> ( Model, Cmd Msg )
update msg model = update msg model =
case msg of case msg of
DownMsg (EncodeDecode.LandingDownMsg (EncodeDecode.TimeUpdate time)) -> DownMsg (EncodeDecode.LandingDownMsg (EncodeDecode.TimeUpdate time)) ->
( { model | time = time }, Cmd.none ) ( { model | time = time }, Cmd.none )
DownMsg (EncodeDecode.LandingDownMsg (EncodeDecode.Greeting greeting)) -> DownMsg (EncodeDecode.LandingDownMsg (EncodeDecode.Greeting greeting)) ->
( { model | greeting = greeting }, Cmd.none ) ( { model | greeting = greeting }, Cmd.none )
UpMsg upMsg -> UpMsg upMsg ->
let cmd = Ports.socketSend <| EncodeDecode.upMsgEncoder <| EncodeDecode.LandingUpMsg upMsg let
cmd =
Ports.socketSend <| EncodeDecode.upMsgEncoder <| EncodeDecode.LandingUpMsg upMsg
in in
( model, cmd ) ( model, cmd )
GreetWidgetText text -> ( {model | greetWidgetText = text}, Cmd.none ) GreetWidgetText text ->
_ -> (model, Cmd.none) ( { model | greetWidgetText = text }, Cmd.none )
_ ->
( model, Cmd.none )
greetWidget : Model -> Element Msg greetWidget : Model -> Element Msg
greetWidget model = greetWidget model =
let let
idleBlue = Element.rgb255 18 147 217 idleBlue =
focusBlue = Element.rgb255 18 125 184 Element.rgb255 18 147 217
myButton = Element.Input.button focusBlue =
Element.rgb255 18 125 184
myButton =
Element.Input.button
[ Element.Background.color idleBlue [ Element.Background.color idleBlue
, Element.mouseOver [ Element.Background.color focusBlue ] , Element.mouseOver [ Element.Background.color focusBlue ]
, Element.width (Element.fill |> Element.maximum 100) , Element.width (Element.fill |> Element.maximum 100)
@ -84,9 +104,15 @@ greetWidget model =
{ onPress = Just <| UpMsg <| EncodeDecode.RequestGreet model.greetWidgetText { onPress = Just <| UpMsg <| EncodeDecode.RequestGreet model.greetWidgetText
, label = Element.text "Greet" , label = Element.text "Greet"
} }
placeholder = case model.greetWidgetText of
"" -> Just <| Element.Input.placeholder [] <| Element.text "Type Your Name" placeholder =
_ -> Just <| Element.Input.placeholder [] <| Element.text "" case model.greetWidgetText of
"" ->
Just <| Element.Input.placeholder [] <| Element.text "Type Your Name"
_ ->
Just <| Element.Input.placeholder [] <| Element.text ""
textInput = textInput =
Element.Input.text Element.Input.text
[ Element.width (Element.fill |> Element.maximum 400) [ Element.width (Element.fill |> Element.maximum 400)
@ -97,17 +123,20 @@ greetWidget model =
, placeholder = placeholder , placeholder = placeholder
, label = Element.Input.labelHidden "Enter your name" , label = Element.Input.labelHidden "Enter your name"
} }
nameInput = Element.row [] [ textInput , myButton]
nameInput =
Element.row [] [ textInput, myButton ]
in in
Element.column [] Element.column []
[ nameInput [ nameInput
, Element.text model.greeting , Element.text model.greeting
] ]
view : Model -> Element Msg view : Model -> Element Msg
view model = view model =
Element.column [] Element.column []
[ Element.text "Landing" [ Element.text "Landing..."
, Element.text <| "Current time is : " ++ model.time , Element.text <| "Current time is : " ++ model.time
, greetWidget model , greetWidget model
] ]