Skip to main content

创建strapi项目

创建

官方

使用 strapi 最新 v4 的版本,按照官网的入门教程进行创建项目。

npx create-strapi-app@latest my-project

一直下一步即可。

使用模板项目

https://github.com/daichangxin/server.strapi_template/generate

使用 npm

我没有使用 yarn,因为在后续使用 docker 时 build 总是大概率卡住报错,偶尔一次才不会超时,应该是网络的原因,配置了.yarnrc文件也无效,所以使用了 npm。

1. 配置.npmrc文件,切换为国内淘宝源

registry="https://registry.npmmirror.com/"
sass_binary_site="https://registry.npmmirror.com/binary.html?path=node-sass/"
phantomjs_cdnurl="https://npmmirror.com/package/downloads"
electron_mirror="https://registry.npmmirror.com/binary.html?path=electron/"
sqlite3_binary_host_mirror="https://foxgis.oss-cn-shanghai.aliyuncs.com/"
profiler_binary_host_mirror="https://registry.npmmirror.com/binary.html?path=node-inspector/"
chromedriver_cdnurl="https://cdn.npmmirror.com/binaries/chromedriver"
sharp_binary_host=https://npmmirror.com/mirrors/sharp
sharp_libvips_binary_host=https://npmmirror.com/mirrors/sharp-libvips

2. 删除本地的 yarn.lock 文件,并执行npm i

执行npm run develop,然后打开http://localhost:1337/admin,环境就算搭建好了。

访问地址

管理后台

http://localhost:1337/admin/

输入管理员账号密码登录,登陆后可以配置 api 的访问权限和编辑数据。

API 访问

http://localhost:1337/api/