当前位置: 首页 > news >正文

网站文章模板面包机做面包网站

网站文章模板,面包机做面包网站,定制网站制作技术,wordpress主页菜单背景#xff1a;我在前端使用vue语言开发的#xff0c;请求的后端是用ThinkPhp项目开发的。我vue项目里的请求php接口#xff0c;自带header参数的跨域问题通过网上查询到的server端配置方法已经解决了。我使用的 是中间件的配置方法#xff1a; ?php//admin 项目 配… 背景我在前端使用vue语言开发的请求的后端是用ThinkPhp项目开发的。我vue项目里的请求php接口自带header参数的跨域问题通过网上查询到的server端配置方法已经解决了。我使用的 是中间件的配置方法 ?php//admin 项目 配置中间件 use app\admin\middleware\MyCrossDomain;return [MyCrossDomain::class ]; MyCrossDomain.php ?php namespace app\admin\middleware;use Closure; use think\Config; use think\Request; use think\Response;/*** 跨域请求支持*/ class MyCrossDomain {protected $cookieDomain;protected $header [Access-Control-Allow-Credentials true,Access-Control-Max-Age 1800,Access-Control-Allow-Methods GET, POST, PATCH, PUT, DELETE, OPTIONS,Access-Control-Allow-Headers Authorization, Code,Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With,];public function __construct(Config $config){$this-cookieDomain $config-get(cookie.domain, );}/*** 允许跨域请求* access public* param Request $request* param Closure $next* param array $header* return Response*/public function handle(Request $request, Closure $next, array $header []): Response{$header !empty($header) ? array_merge($this-header, $header) : $this-header;if (!isset($header[Access-Control-Allow-Origin])) {$origin $request-header(origin);if ($origin ( $this-cookieDomain || str_contains($origin, $this-cookieDomain))) {$header[Access-Control-Allow-Origin] $origin;} else {$header[Access-Control-Allow-Origin] *;}}return $next($request)-header($header);} }这样之后前端项目通过axios接口请求不再报跨域的错了这一阶段的问题已经解决。 现在有一个新的问题我在Thinkphp项目里有一个静态的json文件H5要通过link的方式要请求它。类似这样的 document.write(link relmanifest hrefhttps://landpage-server.appboost.co/admin/file/xxxxx/xxxx.json); 虽然我的ThinkPhp项目已经配置了跨域的但是对于请求这个静态文件还是报跨域的问题。折腾了好久各种配置还是不行。最后我尝试了一种办法就是专门写一个Controller来响应静态文件的返回。代码如下 StaticResourceController.php ?phpnamespace app\admin\controller;use app\admin\model\LogEvents; use app\admin\model\PixelInfo; use app\admin\model\ReleasePlatform; use app\admin\model\ReleaseUrl; use app\admin\model\User; use app\admin\model\Wallet; use app\admin\model\WalletLog; use app\BaseController; use app\Response; use Ramsey\Uuid\Uuid; use think\facade\Console; use think\facade\Db;class StaticResourceController extends MBaseController{public function getManifestJson(){$company_code input(get.code);$promote_code input(get.id);// echo root_path();$root root_path();$dir $root .public/page/;// echo $dir;$content $this-openFile($dir,$company_code,$promote_code);$obj json_decode($content);return json($obj, 200);}public function openFile($dir, $company_code,$promote_code){$filePath $dir.$company_code./.$promote_code..json; // 文件路径$mode r; // 打开模式$fileHandle fopen($filePath, $mode);$content fread($fileHandle, filesize($filePath));if ($fileHandle false) {die(无法打开文件);}fclose($fileHandle);return $content;} } H5端请求是这样的 document.write(link relmanifest hrefhttps://landpage-server.appboost.co/admin/staticResource/getManifestJson?code$company_codeid$promote_code); 谢天谢地终于不报跨域的问题了成功拿到了json静态文件。
http://www.dnsts.com.cn/news/87786.html

相关文章:

  • 电脑机箱定制网站咕果网给企业做网站的
  • 品牌营销型网站建设公司如何建立官网
  • 企业网站的推广方式二手网站专业做附近人的有吗
  • 建设网站方法有哪些内容linx服务器怎么做网站
  • 建设网站用什么时候开始建展公司
  • wordpress访问满网站优化和提升网站排名怎么做
  • 济南网站开发建设哪家做网站的好
  • 苏州网站建设公司科技城微网站建设找哪家公司好
  • 延安网站建设公司电话嘉兴网站托管
  • 聊城房地产网站建设软件开发工程师就是程序员吗
  • 深圳网站官网建设怎么做自己网站产品seo
  • 网站建设正文字体多大合适山东宏远建设有限公司网站
  • 广东住房城乡建设厅网站首页东莞微信网站商城建设
  • 网站主持人制作本机部署wordpress超慢
  • 青岛网站关键词排名优化抓取wordpress站点用户
  • 搭建网站要不要给域名对方汽车网站代码
  • 和魔鬼做交易的网站三亚做网站推广
  • 滁州商业网站建设网建天地小区
  • 网站营销合同信息公开和网站建设工作总结
  • wordpress按钮下拉菜单合肥网站优化服务网
  • 仿阿里云网站做seo要明白网站内容乃重中之重
  • 网站建设费一般摊销几年怎么做私人网站
  • 网站模糊设计做网站公司怎么找客户
  • wordpress栏目管理重庆seo公司排名
  • 游戏网站怎么建设系统之家一键重装
  • 网站做app开发工具asp网站首页模板
  • 中国建设学会查询网站网站的 联系我们怎么做
  • 做网站如何赚钱知乎做什么网站开发最简单
  • 有了域名如何建立网站WordPress 多厂商
  • 石龙镇网站仿做建设网络强国论文