You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在GitHub Codespaces运行Twill CMS时,登录表单路由指向localhost的问题求助

解决TwillCMS在GitHub Codespaces中登录表单Action指向localhost的问题

问题分析

你已在.env中设置APP_URL为Codespaces的访问地址,但Twill登录表单的action仍指向http://localhost:8000/admin/login。这是因为Laravel配置缓存未更新,或是Twill路由生成未正确读取APP_URL,直接修改vendor目录文件并非长久方案(依赖更新后会被覆盖)。

解决步骤

1. 完善.env配置并清除缓存

  • 确保.env中同时配置正确的APP_URL和ASSET_URL(Codespaces环境下需同步资源地址):
    APP_URL=https://xxx-xxx-xxx-8000.app.github.dev
    ASSET_URL=https://xxx-xxx-xxx-8000.app.github.dev
    
  • 执行命令清除Laravel配置、缓存及路由缓存,确保新配置生效:
    php artisan config:clear
    php artisan cache:clear
    php artisan route:clear
    

2. 覆盖Twill登录视图(避免修改vendor文件)

直接修改vendor目录文件会在依赖更新时丢失,建议通过Laravel视图覆盖机制自定义:

  • 在项目resources/views/vendor/twill/auth目录下创建layout.blade.php(目录不存在则手动创建)
  • 复制vendor/area17/twill/views/auth/layout.blade.php的内容到新文件中
  • 修改表单action属性,用Laravel的url()或route()方法生成正确地址:
    <form accept-charset="UTF-8" action="{{ url($route) }}" method="post">...<form>
    
    或直接使用Twill登录路由的命名路由:
    <form accept-charset="UTF-8" action="{{ route('twill.login') }}" method="post">...<form>
    

3. 确认服务器启动方式

在Codespaces中启动Laravel服务器时,需使用允许外部访问的参数:

php artisan serve --host=0.0.0.0 --port=8000

完成以上操作后,登录表单的action会自动指向你设置的Codespaces URL,而非localhost。

内容的提问来源于stack exchange,提问作者fweth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 08:52:38