or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing
xxxxxxxxxx
將Strapi 部署到網路上吧!(Strapi介紹-後篇)
來源: https://strapi.io/documentation/3.0.0-beta.x/guides/deployment.html
前篇(快速入門)
中篇(概念架構介紹)
後篇(部署及設定)
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Step 1. 更改相關設定
將host以及port設為動態設定,能夠在啟動專案時透過更改環境變數的方式,設定其變數
路徑 -
./config/environments/production/server.json
Step 2. 使用AWS S3作為資料host
不使用上傳檔案的功能可以跳過此步驟
AWS在註冊過後大約一天的時間,才能使用S3的功能
透過AWS > 服務 搜尋S3,進入到S3的頁面,會像是以下頁面(此為已建立儲存貯體的畫面)
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →接著開始新增一個儲存貯體吧!
從畫面中的按鈕 +建立儲存貯體
1. 首先輸入名稱,選擇適合專案的區域
2. 設定選項
基本上不用特別勾選,依照你的專案而定
3. 設定許可(重要!!)
不要勾選
封鎖透過新的存取控制清單 (ACL) 授與的對儲存貯體和物件的公開存取權不要勾選
封鎖透過任何存取控制清單 (ACL) 授與的儲存貯體和物件的公開存取權4. 檢閱,並點擊建立儲存貯體
儲存貯體已建立完成,接著需要在strapi中安裝aws s3的插件以及設定相關密鑰才能在strapi中使用AWS S3的服務,可以在完成後試著上傳一個檔案來測試AWS S3的功能
5. 安裝AWS S3的provider插件
npm install strapi-provider-upload-aws-s3@beta
完成後在strapi admin,選擇擴充功能中的FILES UPLOAD的設定(齒輪)
在儲存空間的選單中,會多了Amazon Web Service S3的選項就表示成功了!
而我們等一下部署到heroku再來設定Token
如下圖

Step 3. 部署到Heroku
僅介紹Heroku平台方式,原文中還有其他像是AWS, Degital Ocean…的方式
(Heroku使用的資料庫add-on為Postgres)
安裝及登入Heroku
安裝:
mac:
brew tap heroku/brew && brew install heroku
windows: 直接使用安裝檔 64bit / 32bit
ubuntu:
sudo snap install --classic heroku
登入:
heroku login
來登入(或是使用heroku網站的登入也可以)新建Strapi專案 / 使用既有專案
新建專案:
strapi new my-project --quickstart
新建專案如要使用AWS請依照AWS S3的步驟設定
修改
.gitignore
將
package-lock.json
這行 加入.gitignore
以免出錯git 上傳
路徑 -
./你的專案/
創建新的Heroku專案
路徑 -
./你的專案/
heroku create
或是自訂專案名稱heroku create custom-project[自訂專案名稱]
設定Heroku的資料庫(PostgresSQL addOn 為例)
路徑 -
./你的專案/
在heroku專案新增postgresQL的插件
heroku addons:create heroku-postgresql:hobby-dev
取得資料庫相關設定
heroku config
會取得像是以下資料格式
ostgres://ebitxebvixeeqd:dc59b16dedb3a1eef84d4999sb4baf@ec2-50-37-231-192.compute-2.amazonaws.com: 5432/d516fp1u21ph7b
資料分別為
postgres:// USERNAME : PASSWORD @ HOST : PORT : DATABASE_NAME
將要依此做以下資料庫的設定,相關參數請填入你在heroku config拿到的設定
更新 strapi資料庫檔案的設定
路徑 -
./你的專案/config/environments/production/database.json
安裝
pg
(postgres套件)路徑 -
./你的專案/
npm install pg --save
上傳剛剛更新的修改,完成!!
接著你就可以在已部署的網頁中取得API了
使用方法與localhost方法一樣,只是網址改為heroku專案的網址
如果403 forbidden,admin 頁面中的身份與權限,有相關API使用的設定,詳見前篇(快速入門)
如需無法使用graphQL,請安裝graphQL插件並修改其設定檔,詳見前篇(快速入門)
補充設定AWS S3(可以跳過)
測試上傳:
(如果AWS S3沒成功,請先在AWS S3上傳一個檔案,或是依照之前的設定重新設定一次)
步驟圖示說明
點擊我的安全登入資料

點擊存取金鑰,並建立新的存取金鑰

填入金鑰和其他東西(要選擇production的tab)

上傳成功!

備註: 更新strapi專案
一樣也是將檔案上傳到heroku並發布
路徑 -
./你的專案/