一個範例電子商務/零售軟體解決方案,展示了 MongoDB 的強大功能和靈活性。
MEANStore 利用 vagrant 來提供運行 MEANStore / MEANMart 的功能齊全的虛擬環境。
git clone https://github.com/mrlynn/meanstore.git
cd meanstore
vagrant up
此時,應用程式應該已啟動並正在運行,並且可以透過開啟 URL http://localhost:30001 從筆記型電腦/桌上型電腦進行訪問
vagrant ssh # access the vagrant instance
sudo su - # become super user
cd /home/vagrant/meanmart/meanstore # change to project directory
npm run dev # run the application in developer mode
此時,應用程式應該已啟動並正在運行,並且可以透過打開URL http://127.0.0.1:30000 從筆記型電腦/桌上型電腦存取該應用程序,具體取決於.env.hackathon 設定檔中的具體設置。
git clone https://github.com/mrlynn/meanstore.git
cd meanstore
npm install
# unicode doesn't install nicely first pass - try again
npm install unicode
# install faker to generate data
npm install faker
# Set environment
export MONGODB_URI="mongodb://127.0.0.1:27017/hackathon"
# Generate some data...
node data/fake-refrigerators.js
node data/fake-televisions.js
node data/fake-cameras.js
node data/fake-apparel.js
# Create the categories...
node data/category-seeder.js
# Now run it...
npm run dev
vagrant 完成配置後,透過 ssh 進入實例:
vagrant ssh
您應該會發現 MongoDB 已安裝並正在運行。您還應該發現已經建立了一個資料庫和一組包含測試資料的集合。
若要使用任何包含的 API 或 OAuth 驗證方法,您需要取得適當的憑證:用戶端 ID、用戶端金鑰、API 金鑰或使用者名稱和密碼。您將需要透過每個提供者來產生新的憑證。
MEANStore 1.0 更新:我為所有 API 範例提供了虛擬金鑰和密碼,以便您更快啟動和運行。但當您準備好部署應用程式時,請不要忘記使用您的憑證更新它們。
- 存取Google Cloud Console - 點擊**建立項目** 按鈕- 輸入*項目名稱*,然後點擊**建立** 按鈕- 然後點擊側邊欄中的*API 和auth* 並選擇*API*選項卡- 點擊*社交API* 下的**Google+ API**,然後點擊**啟用API** - 接下來,在側邊欄中的*API 和身份驗證* 下,點擊*憑證*選項卡- 點擊**建立新客戶端ID ** 按鈕- 選擇*Web 應用程式* 並點擊**配置同意畫面** - 填寫必填字段,然後點擊**儲存** - 在*創建客戶端ID* 模式對話方塊中: - **應用程式類型* *:Web 應用程式- **授權的Javascript 來源**:http://localhost:3000 - **授權的重定向URI**:http ://localhost:3000/auth/google/callback - 點擊**建立客戶端ID ** 按鈕 - 將 *Client ID* 和 *Client Secret* 金鑰複製並貼上到 `.env` 中注意:當您準備部署到生產時,請不要忘記將新網址新增至Authorized Javascript origins和Authorized redirect URI ,例如http://my-awesome-app.herokuapp.com
和http://my-awesome-app.herokuapp.com/auth/google/callback
分別為http://my-awesome-app.herokuapp.com/auth/google/callback
。其他提供者也是如此。
注意:成功登入 Facebook 後,使用者將被重定向回主頁,並在 URL 中附加哈希#_=_
。這不是一個錯誤。有關處理方法,請參閱 Stack Overflow 討論。
MEANStore 附帶一個 API,讓您能夠查詢和管理 MongoDB 資料庫。如果您想查看內部資料結構以了解如何使用 MongoDB 基於文件的資料儲存方法建立產品目錄,一個很好的開始方法是使用 Postman。使用 Postman,您可以快速建立請求,保存它們以供以後使用,並分析 API 發送的回應。 Postman 可以大幅減少測試和開發 API 所需的時間。 Postman 同樣適用於個人開發人員、小型團隊或大型組織。
要利用 postman,安裝後,只需將 API 的 url 載入到 postman 中即可。例如,如果您使用基於 vagrant 的安裝,請查看產品集合,請在 postman 中使用以下 url:
http://localhost:30000/api/products
這將公開整個產品目錄集合。
[
{
"_id": "584aecaaf580422022aea4fb",
"code": "ref1099",
"name": "Generic Plastic Computer Refrigerator",
"title": "Intelligent IVORY Generic Plastic Computer Refrigerator",
"description": "Est enim aut.",
"taxable": true,
"shipable": true,
"price": 73300,
"Product_Group": "Refrigerator",
"category": "Refrigerator",
"imagePath": "/img/samsung-refrigerator.jpg",
"__v": 0,
"salesYearMonth": [],
"salesYTD": [],
"usersBought": [],
"categories": [],
"update": "2016-12-09T17:40:58.033Z",
"created": "2016-12-09T17:40:58.033Z",
"options": [],
"Attributes": [],
"likes": []
},
...
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature