Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for update node version #840

Open
wants to merge 104 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
3232ef6
feat: test
arthur-kuo Jun 6, 2023
04cf061
Merge pull request #1 from mamadoujiaohao/feature
elviawu Jun 7, 2023
d5f5b7c
feat: add user,tweet,like,reply,followship models and seeders
elviawu Jun 7, 2023
b28569d
Merge branch 'master' into feature
arthur-kuo Jun 7, 2023
79bfeb6
Merge pull request #2 from mamadoujiaohao/feature
arthur-kuo Jun 7, 2023
fba98f3
feat: add routes: user/register & user/login & admin/login
arthur-kuo Jun 7, 2023
33c3d8f
feat: add routes: user/register & user/login & admin/login
arthur-kuo Jun 7, 2023
c20e139
feat: fix conflict
arthur-kuo Jun 7, 2023
a9992e4
feat: edit passport for users/signin
arthur-kuo Jun 7, 2023
61c846f
feat: edit passport for users/signin
arthur-kuo Jun 7, 2023
8586dd2
feat: edit login/register routers
arthur-kuo Jun 7, 2023
525e157
feat: add back _helpers.js
arthur-kuo Jun 7, 2023
fab7960
feat: add get tweets and get tweets:id api
elviawu Jun 8, 2023
5756a1d
Merge branch 'master' of https://github.com/mamadoujiaohao/twitter-ap…
elviawu Jun 8, 2023
6e102fa
Merge branch 'feature' of https://github.com/mamadoujiaohao/twitter-a…
elviawu Jun 8, 2023
e598939
Merge pull request #3 from mamadoujiaohao/B02
arthur-kuo Jun 8, 2023
2f404e2
feat: edit passport
arthur-kuo Jun 8, 2023
4c2b51e
feat: edit passport again
arthur-kuo Jun 8, 2023
c9f57db
feat: git pull feature
arthur-kuo Jun 8, 2023
0c61f2d
Merge branch 'A03' into feature
arthur-kuo Jun 8, 2023
decc960
feat: edit passport
arthur-kuo Jun 8, 2023
2a0073d
Merge branch 'master' into feature
arthur-kuo Jun 8, 2023
9e77797
feat: add user and admin routes
elviawu Jun 8, 2023
24daaab
Merge pull request #4 from mamadoujiaohao/feature
arthur-kuo Jun 8, 2023
d65272a
feat: add post, put, reply, like tweets routes
elviawu Jun 9, 2023
fd8f6be
feat: add 'delete tweet' feature to admin
arthur-kuo Jun 9, 2023
2c02d9f
Merge pull request #5 from mamadoujiaohao/feature
elviawu Jun 9, 2023
1ae6aa1
feat: add followship routes
elviawu Jun 9, 2023
17c193e
Merge branch 'feature' of https://github.com/mamadoujiaohao/twitter-a…
elviawu Jun 9, 2023
cb464e1
Merge branch 'B03' into feature
elviawu Jun 10, 2023
af788dc
feat: add getUserInfo
arthur-kuo Jun 10, 2023
fba2f10
Merge pull request #6 from mamadoujiaohao/feature
arthur-kuo Jun 10, 2023
08d8871
feat: add get tweets and get tweets:id api
elviawu Jun 8, 2023
052d052
feat: ready to push to heroku 1st time (edit passport & middleware)
arthur-kuo Jun 10, 2023
72dda92
feat: ready to push to heroku 1st time (edit routes/module/users.js)
arthur-kuo Jun 10, 2023
6271643
Merge pull request #7 from mamadoujiaohao/feature
elviawu Jun 10, 2023
9ff9a81
Merge branch 'master' of https://github.com/mamadoujiaohao/twitter-ap…
elviawu Jun 10, 2023
474355e
feat: add editUserInfo (can't edit avatar/cover yet)
arthur-kuo Jun 10, 2023
2e6d77d
feat: add getUserTweets
arthur-kuo Jun 10, 2023
194e943
feat: ready to push to heroku 2st time
arthur-kuo Jun 10, 2023
d4f8dcc
Merge pull request #9 from mamadoujiaohao/feature
elviawu Jun 10, 2023
467b061
feat: ready to push to heroku 2st time(edit Procfile & config.json)
arthur-kuo Jun 10, 2023
c55094b
Merge branch 'A06' into feature
arthur-kuo Jun 10, 2023
43d0fcf
Merge pull request #10 from mamadoujiaohao/feature
elviawu Jun 10, 2023
52b4ce7
Merge branch 'master' of https://github.com/mamadoujiaohao/twitter-ap…
elviawu Jun 10, 2023
d8d7fef
feat: add getUserReplies & getUserLikes
arthur-kuo Jun 11, 2023
c1165d0
modify app.js and userController
elviawu Jun 11, 2023
d2d3839
install multer and imgur
elviawu Jun 11, 2023
b983ea5
feat: add getUserFollowings & getUserFollowers
arthur-kuo Jun 11, 2023
e64cc28
feat: add getTopUsers
arthur-kuo Jun 11, 2023
eb823a9
feat: sort responed data
arthur-kuo Jun 11, 2023
b2bbeeb
Merge pull request #11 from mamadoujiaohao/feature
elviawu Jun 11, 2023
40de139
Merge branch 'master' of https://github.com/mamadoujiaohao/twitter-ap…
elviawu Jun 12, 2023
2c572ac
Merge branch 'master' into B05
elviawu Jun 12, 2023
1fa5281
modify model/index
elviawu Jun 12, 2023
2b4a3a2
Merge branch 'B05' into feature
elviawu Jun 12, 2023
402ea4b
modify models for test
elviawu Jun 12, 2023
b064563
Merge branch 'B05' into feature
elviawu Jun 12, 2023
e932079
Merge pull request #13 from mamadoujiaohao/feature
arthur-kuo Jun 12, 2023
323e774
feat: add cors package
elviawu Jun 12, 2023
9e12e17
Merge pull request #14 from mamadoujiaohao/B06
arthur-kuo Jun 12, 2023
939dd6a
feat: fix'editUserInfo user could commit the same account/email with …
arthur-kuo Jun 12, 2023
5ca2157
feat: edit api-auth & getUsers in admin-controller
arthur-kuo Jun 13, 2023
1436a33
Merge pull request #15 from mamadoujiaohao/feature
elviawu Jun 13, 2023
71bb25a
feat: edit editUserInfo
arthur-kuo Jun 13, 2023
b779856
modify controllers for tests
elviawu Jun 13, 2023
42572d1
Merge branch 'master' into B07
elviawu Jun 13, 2023
ddee94f
Merge pull request #16 from mamadoujiaohao/B07
arthur-kuo Jun 13, 2023
fd8df79
Merge branch 'feature' into A08
arthur-kuo Jun 13, 2023
3734fc5
Merge branch 'B07' into feature
elviawu Jun 13, 2023
42ef622
feat: add isFollowed(Boolean) to the reponse of getUserInfo
arthur-kuo Jun 13, 2023
92a571c
feat: fix image upload function
arthur-kuo Jun 13, 2023
8afcc0e
feat: assure every asynchronous part is useing async function
arthur-kuo Jun 13, 2023
fc19602
feat: assure every asynchronous part is useing async function
arthur-kuo Jun 13, 2023
5ce0bc6
feat: add isFollowed into the response of getTopUsers
arthur-kuo Jun 14, 2023
f8f1750
feat: edit postTweet
arthur-kuo Jun 14, 2023
932baaf
Merge pull request #17 from mamadoujiaohao/feature
elviawu Jun 14, 2023
04b8314
Merge branch 'feature' of https://github.com/mamadoujiaohao/twitter-a…
elviawu Jun 14, 2023
efdf621
Merge branch 'feature'
elviawu Jun 14, 2023
361fd94
modify controllers for test/requests
elviawu Jun 14, 2023
a302baf
Merge pull request #18 from mamadoujiaohao/B08
arthur-kuo Jun 14, 2023
c720ef7
feat: edit cors (access-control-allow-origin: '*')
arthur-kuo Jun 14, 2023
a83e501
Merge pull request #19 from mamadoujiaohao/feature
elviawu Jun 14, 2023
3f902ea
feat: edit error-handler(change status code of error states)
arthur-kuo Jun 14, 2023
66c5869
Merge pull request #20 from mamadoujiaohao/feature
elviawu Jun 14, 2023
8a6943b
feat: add auth router
arthur-kuo Jun 15, 2023
af802bd
Merge pull request #21 from mamadoujiaohao/feature
elviawu Jun 15, 2023
88efd89
feat: fix auth-controller
arthur-kuo Jun 15, 2023
2117725
Merge pull request #22 from mamadoujiaohao/feature
elviawu Jun 15, 2023
ea3c8c1
add readme and modify like model for test
elviawu Jun 15, 2023
cd4db01
Merge pull request #23 from mamadoujiaohao/B09
arthur-kuo Jun 15, 2023
ca60de6
Merge branch 'feature'
elviawu Jun 16, 2023
84b8d5f
Merge branch 'master' of https://github.com/mamadoujiaohao/twitter-ap…
elviawu Jun 16, 2023
843cd31
feat: add like and followship seeders and modify error messages
elviawu Jun 16, 2023
e91904f
modify postLike and postUnlike in controller
elviawu Jun 16, 2023
01a0c5e
Merge pull request #24 from mamadoujiaohao/B10
arthur-kuo Jun 16, 2023
27b2195
feat: install socket.io
elviawu Jun 18, 2023
02b534b
feat:-uninstall bcrypt-nodejs
arthur-kuo Jun 18, 2023
f909b33
feat: fix getTopUsers
arthur-kuo Jun 18, 2023
c285a6c
Merge pull request #25 from mamadoujiaohao/feature
elviawu Jun 18, 2023
dbd5ebe
update node version
elviawu Jun 19, 2023
7c4fc68
modify npm run test at package.json
elviawu Jun 19, 2023
d903d6e
modify jwt_secret
elviawu Jun 19, 2023
c7e3a72
Merge branch 'master' into B11
arthur-kuo Jun 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
JWT_SECRET=alphacamp
SESSION_SECRET=secret
IMGUR_CLIENT_ID=
PORT=
HEROKU_PAGE=
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules/*
/test/*
12 changes: 12 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
env:
browser: true
commonjs: true
es2021: true
extends:
- standard
parserOptions:
ecmaVersion: 12
rules:
arrow-parens:
- warn
- as-needed
53 changes: 53 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
* text=auto

# Source code
*.css text diff=css
*.html text diff=html
*.js text
*.json text

# Documentation
*.markdown text diff=markdown
*.md text diff=markdown
*.txt text

# Templates
*.handlebars text
*.hbs text

# Configs
*.cnf text
*.conf text
*.config text
.editorconfig text
.env text
.env.* text
.gitattributes text
.gitconfig text
*.lock text -diff
package.json text eol=lf
package-lock.json text -diff
yarn.lock text -diff
*.yaml text
*.yml text
browserslist text

# Heroku
Procfile text

# Graphics
*.gif binary
*.ico binary
*.jpg binary
*.jpeg binary
*.pdf binary
*.png binary
# SVG treated as an asset (binary) by default.
*.svg text
# If you want to treat it as binary,
# use the following line instead.
# *.svg binary
*.webp binary

# Ignore files (like .npmignore or .gitignore)
*.*ignore text
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ build/Release
# Dependency directories
node_modules/
jspm_packages/
temp/

# TypeScript v1 declaration files
typings/
Expand Down Expand Up @@ -84,4 +85,5 @@ typings/
.fusebox/

# DynamoDB Local files
.dynamodb/
.dynamodb/

1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: NODE_ENV=production node app.js
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Simple Twitter
![markdown](https://i.imgur.com/AAQaM0Z.png "Login Page")
## 介紹
利用前後端分離的方式,打造一個類Twitter的社群平台"Alphitter",前端使用React框架,後端使用Express框架與MySQL關聯式資料庫,使用者可在平台建立帳號,新增、瀏覽、更新、刪除貼文,並追蹤其他使用者。
## Features功能
• 使用者可註冊帳號登入,編輯自己資料
• 新增、瀏覽、更新、刪除貼文
• 於貼文按讚或留言
• 追蹤其他使用者
## 前端網站連結
https://tales91817.github.io/simple-twitter
## API - 接口文件
提供每個API的使用方式與所回應格式與資訊
https://www.notion.so/Twitter_api_2020-80b7a66e89514f638eea161d028e765b
## Environment Setup 環境建置
• Node.js 18.16.0
• nodemon

## Install安裝與使用
1. 確認安裝Node.js和npm之後,將專案 clone 到本地
```
https://github.com/mamadoujiaohao/twitter-api-2020.git
```
2. 透過終端機進入此專案資料夾,安裝所需NPM Packages:
```
npm install
```
3. 在SQL WorkBench 建立資料庫 (在workBench內輸入):
```
create database ac_twitter_workspace
```
4. 建立資料庫Table:
```
npx sequelize db:migrate
```
5. 在資料庫建立種子資料:
```
npx sequelize db:seed:all
```
6. 在.env檔案中放入密碼(參考.env.example):
```
IMGUR_CLIENT_ID= 你的密碼
JWT_SECRET= 你的密碼
```
7. 啟動伺服器
```
npm run start
```
8. 若看見此行訊息則代表順利運行,打開瀏覽器進入到以下網址
```
Example app listening on http://localhost:3000
```
9. 若欲暫停使用
```
ctrl + c
```
10. 測試帳號
```
• 管理者帳號-後台
account: root
email: [email protected]
password: 12345678
• 使用者帳號-前台
account: user0~user4
email: [email protected] ~ [email protected]
password: 12345678
```
9 changes: 4 additions & 5 deletions _helpers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

function getUser(req) {
return req.user;
function getUser (req) {
return req.user
}

module.exports = {
getUser,
};
getUser
}
31 changes: 24 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config()
}
const express = require('express')
const helpers = require('./_helpers');
const session = require('express-session')
const SESSION_SECRET = 'secret'
const passport = require('./config/passport')
const methodOverride = require('method-override')
const cors = require('cors')
const routes = require('./routes')

const corsOptions = {
origin: '*',
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
allowedHeaders: ['Content-Type', 'Authorization']
}

const app = express()
const port = 3000
const port = process.env.PORT || 3000

// use helpers.getUser(req) to replace req.user
function authenticated(req, res, next){
// passport.authenticate('jwt', { ses...
};
app.use(express.urlencoded({ extened: true }))
app.use(express.json())
app.use(session({ secret: SESSION_SECRET, resave: false, saveUninitialized: false }))
app.use(passport.initialize())
app.use(passport.session())
app.use(methodOverride('_method'))
app.use(cors(corsOptions))
app.use(routes)

app.get('/', (req, res) => res.send('Hello World!'))
app.listen(port, () => console.log(`Example app listening on port ${port}!`))

module.exports = app
6 changes: 1 addition & 5 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
"logging": false
},
"production": {
"username": "root",
"password": null,
"database": "database_production",
"host": "127.0.0.1",
"dialect": "mysql"
"use_env_variable": "CLEARDB_DATABASE_URL"
},
"travis": {
"username": "travis",
Expand Down
67 changes: 66 additions & 1 deletion config/passport.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,70 @@
const passport = require('passport')
const LocalStrategy = require('passport-local')
const bcrypt = require('bcryptjs')
const { User, Tweet, Followship } = require('../models') // 之後要改成{ User } = require('../models')
const passportJWT = require('passport-jwt')
const JWTStrategy = passportJWT.Strategy
const ExtractJWT = passportJWT.ExtractJwt

passport.use(new LocalStrategy(
// customize user field
{
usernameField: 'account',
passwordField: 'password',
passReqToCallback: true // 如果需要在 verify callback 中取得 req
},
// authenticate user
// 因為上面有註明 passReqToCallback: true,所以第一個參數會是 req
async (req, account, password, cb) => {
try {
const user = await User.findOne({ where: { account } })
if (!user) throw new Error('帳號不存在!')
const comparePassword = await bcrypt.compare(password, user.password)
if (!comparePassword) throw new Error('密碼錯誤!')
return cb(null, user)
} catch (err) {
return cb(err, null)
}
}
))

const jwtOptions = {
jwtFromRequest: ExtractJWT.fromAuthHeaderAsBearerToken(),
secretOrKey: process.env.JWT_SECRET || 'alphacamp'
}

module.exports = passport
passport.use(new JWTStrategy(jwtOptions, async (jwtPayload, cb) => {
try {
const user = await User.findByPk(jwtPayload.id, {
include: [
{ model: Tweet, as: 'LikedTweets' },
{ model: User, as: 'Followers' },
{ model: User, as: 'Followings' }
]
})
return cb(null, user)
} catch (err) {
return cb(err, null)
}
}))

passport.serializeUser((user, cb) => {
cb(null, user.id)
})

passport.deserializeUser(async (id, cb) => {
try {
const user = await User.findByPk(id, {
include: [
{ model: Tweet, as: 'Tweets' },
{ model: Followship, as: 'Followers' },
{ model: Followship, as: 'Followings' }
]
})
return cb(null, user.toJSON())
} catch (err) {
return cb(err, null)
}
})

module.exports = passport
Loading