• mojolicious perl web 框架学习一


    以前是通过传统模式安装的,以下是通过perlbrew 安装以及使用

    安装perlbrew

    参考https://perlbrew.pl/

    安装perl

    注意选择需要5.20 以及的版本

    perlbrew install perl-5.32.0
    perlbrew switch perl-5.32.0

    安装mojolicious

    基于以上配置的perl 环境

    curl -L https://cpanmin.us | perl - -M https://mirrors.tuna.tsinghua.edu.cn/CPAN/ -n Mojolicious

    使用cli 命令

    • 支持的cli
    Usage: APPLICATION COMMAND [OPTIONS]
      mojo version
      mojo generate lite-app
      ./myapp.pl daemon -m production -l http://*:8080
      ./myapp.pl get /foo
      ./myapp.pl routes -v
    Tip: CGI and PSGI environments can be automatically detected very often and
         work without commands.
    Options (for all commands):
      -h, --help          Get more information on a specific command
          --home <path>   Path to home directory of your application, defaults to
                          the value of MOJO_HOME or auto-detection
      -m, --mode <name>   Operating mode for your application, defaults to the
                          value of MOJO_MODE/PLACK_ENV or "development"
    Commands:
     cgi       Start application with CGI
     cpanify   Upload distribution to CPAN
     daemon    Start application with HTTP and WebSocket server
     eval      Run code against application
     generate  Generate files and directories from templates
     get       Perform HTTP request
     inflate   Inflate embedded files to real files
     prefork   Start application with pre-forking HTTP and WebSocket server
     psgi      Start application with PSGI
     routes    Show available routes
     version   Show versions of available modules
    See 'APPLICATION help COMMAND' for more information on a specific command.
    • 创建一个项目
    mojo generate lite-app demoapp

    效果


    • 运行
     
    morbo demoapp
    • 部署
      推荐基于hypnotoad
     
    hypnotoad ./demoapp
    • 容器部署模式
      参考
     
    FROM perl:5.26
    RUN cpan install  Mojolicious::Lite 
        && mkdir -p /usr/src/app
    WORKDIR /usr/src/app
    COPY demoapp /usr/src/app/
    ENTRYPOINT [ "sh","/usr/src/app/demoapp","daemon","-m","production","-l","http://*:8080" ]

    参考资料

    https://perlbrew.pl/
    https://mojolicious.org/
    http://mirrors.ustc.edu.cn/
    https://docs.mojolicious.org/Mojo/Server/Hypnotoad

  • 相关阅读:
    第十八课 顺序存储线性表的分析
    第十七课 StaticList和DynamicList实现
    第十六课 顺序存储结构的抽象实现
    第十五课 线性表的顺序存储结构
    第十四课 线性表的本质和操作
    第十三课 类族结构的进化
    第十二课 顶层父类的创建
    第十一课 异常类构建
    HDU 5773The All-purpose Zero
    HDU 5755 Gambler Bo
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/14165730.html
Copyright © 2020-2023  润新知