Skip to content

Commit

Permalink
Merge branch 'dev' into feature/github-login
Browse files Browse the repository at this point in the history
  • Loading branch information
rockpell authored Nov 26, 2020
2 parents d7a8ad3 + e4ba110 commit a5a6337
Show file tree
Hide file tree
Showing 25 changed files with 843 additions and 129 deletions.
8 changes: 8 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This is a comment.
# Each line is a file pattern followed by one or more owners.

# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence,
# @global-owner1 and @global-owner2 will be requested for
# review when someone opens a pull request.
* @boostcamp-2020/project12-c
8 changes: 8 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Linked Issue
close #

## κ³΅μœ ν•  사항
-

## λ…Όμ˜ν•  사항
- μ—†μŠ΅λ‹ˆλ‹€. ❌
7 changes: 4 additions & 3 deletions backend/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('dotenv').config()
import express from 'express'
import path from 'path'
import cookieParser from 'cookie-parser'
Expand All @@ -8,9 +9,8 @@ import statusCode from './util/statusCode'
import resMessage from './util/resMessage'
import passport from 'passport'
import passportConfig from './config/passport'
const cors = require('cors')

require('dotenv').config()
import './chatServer'
import cors from 'cors'

const app = express()

Expand All @@ -25,6 +25,7 @@ mongoose
.catch(err => console.error(err))

app.use(logger('dev'))
app.use(cors({ origin: true, credentials: true }))
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(express.static(path.join(__dirname, '../dist')))
Expand Down
31 changes: 31 additions & 0 deletions backend/chatServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { config as dotenv } from 'dotenv'
import express from 'express'
import { createServer } from 'http'
import createChatServer from 'socket.io'
dotenv()

const server = createServer(express())
const io = createChatServer(server, {
cors: { origin: process.env.FRONTEND_HOST, credentials: true },
})

const namespace = io.of('chat')
namespace.use((socket, next) => {
// TODO jwt 검증 둜직 ν•„μš”
next()
})

namespace.on('connection', socket => {
socket.on('new message', data => {
// TODO νŠΉμ • μ±„λ„λ‘œ μ „μ†‘ν•˜λ„λ‘ λ³€κ²½, db에 μ €μž₯ ν•„μš” (ν˜„μž¬λŠ” μžμ‹  μ œμ™Έ 전체 전솑)
socket.broadcast.emit('new message', {
message: data,
})
})
})

server.listen(process.env.CHAT_PORT, () => {
console.log('chat server created 4000')
})

export default server
12 changes: 12 additions & 0 deletions backend/controller/channel/channel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { asyncWrapper } from '../../util'
import service from '../../service/channel'

const createChannel = asyncWrapper(async (req, res) => {
const { code, success, data } = await service.createChannel({
...req.body,
creator: req.user,
})
return res.status(code).json({ success, data })
})

module.exports = { createChannel }
8 changes: 8 additions & 0 deletions backend/controller/channel/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import express from 'express'
import controller from './channel'

const router = express.Router()

router.post('/', controller.createChannel)

module.exports = router
6 changes: 2 additions & 4 deletions backend/controller/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import express from 'express'
import userController from './user'
import channelController from './channel'

const router = express.Router()

/* GET home page. */
router.get('/', function (req, res, next) {
res.json({ success: true })
})
router.use('/channel', channelController)

router.use('/user', userController)

Expand Down
Loading

0 comments on commit a5a6337

Please sign in to comment.