跳至主要內容

文章

顯示從 11月, 2022 起發佈的文章

git 使用筆記

以下為常用指令 Git Bash git config --global user.name "a b" 設定使用者名稱 git config --global user.email ddd@sss.asd 設定使用者電子郵件 git config --global core-editor "code --wait" 設定 vs code 為文字編輯程式 git config --global -e 查看目前設定參數 git config --global core.autocrlf [true|input] windows,Mac/Linux 用 input git config --help 打開幫助網頁 git config --h 查看指令 [start|open] [filename] 開啟檔案 [windows|Mac] 常見問題 .gitignore 無效。 這個問題會發生,常常是因為要忽略的檔案在創建 .gitignore 前就已經發上去 staging area 了。 所以要將該檔案從上面移除即可。 git rm -h 列出指令列表。 git rm -r --cached [filename]  設定 vscode 視覺化 git config --global diff.tool vscode git config --global difftool.vscode.cmd "code --wait --diff $LOCAL $REMOTE" 常用 git 指令 git log --oneline [--reverse]簡短紀錄 git show [id] 細看紀錄 git show HEAD[~0][:filename] 細看最近紀錄

Cors 基礎設定

建立一個 API 伺服器要設定 Access-Control-Allow-Origin,這樣別的網站才能呼叫, Koa  如果適用 Koa,只要做一個 mideleware 設定即可。 app.use(async (ctx, next) => { ctx.set('Access-Control-Allow-Origin', '*'); await next(); }); Express app.use(async (ctx, next) => { res.set('Access-Control-Allow-Origin', '*') }); 如果只允許一個網域呼叫 將 * 換成該網域即可。 如果允許多個網域呼叫 使用 Swich 的方式,先讀取前端傳來得 headers.origin 來決定設定的 access 即可。3 其他設定 另外,還有 Access-Control-Allow-Methods 跟  Access-Control-Allow-Headers 可以設定,舉例來說,最近我做了一個 Koa.js 應用程式,就要設定 Access-Control-Allow-Headers 包括 content-type 才能傳送 post 請求。