Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.

[yejeong, hyoon, sucho] - 피신 끝!!! #4

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bf169dc
init backend dir
sungyongcho Aug 30, 2021
deb5e49
create react app as frontend
kamg2218 Aug 30, 2021
b68a354
test
sungyongcho Aug 30, 2021
675082d
test
sungyongcho Aug 30, 2021
3151bd8
예제코드 작성
sungyongcho Aug 30, 2021
38257e8
Merge pull request #1 from Yenowme/feature/socketio
Yenowme Aug 30, 2021
093dac5
인디언 포커 로직 작성 완료
sungyongcho Aug 30, 2021
3ac43d2
인디언 포커 로직 분리
sungyongcho Aug 30, 2021
1dca43b
인디언 포커 로직 구현
sungyongcho Aug 30, 2021
70bac98
시간 값 turnTime 추가
sungyongcho Aug 30, 2021
1b4344e
feat: express setting
Yenowme Aug 30, 2021
b7e37d5
socket.io server/client 분리, 테스트
sungyongcho Aug 30, 2021
d83ad0d
feat: google OAuth login
Yenowme Aug 30, 2021
ac88fd2
login page and game page
kamg2218 Aug 30, 2021
c1a21c7
update package.json
kamg2218 Aug 31, 2021
ca7332d
Merge pull request #2 from Yenowme/hyoon
Yenowme Aug 31, 2021
0a5b84d
feat: Oauth 통신 에러
Yenowme Aug 31, 2021
4f1993c
game title
kamg2218 Aug 31, 2021
4aa30be
Merge branch 'develop' into feature/OAuth
Yenowme Aug 31, 2021
941abad
react 셋업중
sungyongcho Aug 31, 2021
5bec013
ha...
sungyongcho Aug 31, 2021
39bf26a
set withCredentials:true
Yenowme Aug 31, 2021
2a96846
frontend
kamg2218 Aug 31, 2021
4913578
Merge pull request #3 from Yenowme/hyoon
Yenowme Aug 31, 2021
a1d4c38
Merge branch 'develop' into feature/OAuth
Yenowme Aug 31, 2021
82bb545
Merge pull request #4 from Yenowme/feature/OAuth
Yenowme Aug 31, 2021
f3e1b2b
Merge branch 'feature/socketio' into develop
sungyongcho Aug 31, 2021
4b4504e
update Game.js
kamg2218 Aug 31, 2021
741a0f5
Merge branch 'develop' of github.com:Yenowme/piscine-rush01 into develop
kamg2218 Aug 31, 2021
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
6 changes: 6 additions & 0 deletions backend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PORT = 4242

GOOGLE_CLIENT_ID = 246244101947-q1er4l7n45jct7c8camsis7vo6ljq488.apps.googleusercontent.com
GOOGLE_CLIENT_PW = Yw_jmLPvimX29H9ClMXgsGuD
CALLBACK_URL = /google/callback
COOKIE_KEY = secret
1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
44 changes: 44 additions & 0 deletions backend/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require("dotenv").config();
const session = require("express-session");

var express = require("express");
var path = require("path");
var cookieParser = require("cookie-parser");
var logger = require("morgan");
const passport = require("passport");
const passportConfig = require("./passport");
var indexRouter = require("./routes/index");
var usersRouter = require("./routes/users");
const cookieSession = require("cookie-session");
var app = express();
const cors = require("cors");

app.use(
cookieSession({
maxAge: 60 * 60 * 1000,
keys: [process.env.COOKIE_KEY],
})
);

app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));

app.use(passport.initialize());
app.use(passport.session());
passportConfig();

app.use(
cors({
origin: "http://localhost:3000", // allow to server to accept request from different origin
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
credentials: true, // allow session cookie from browser to pass through
})
);

app.use("/", indexRouter);
app.use("/users", usersRouter);

module.exports = app;
87 changes: 87 additions & 0 deletions backend/bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/
require("dotenv").config();

var app = require("../app");
var debug = require("debug")("backend:server");
var http = require("http");

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || "3000");
app.set("port", port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on("error", onError);
server.on("listening", onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== "listen") {
throw error;
}

var bind = typeof port === "string" ? "Pipe " + port : "Port " + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case "EACCES":
console.error(bind + " requires elevated privileges");
process.exit(1);
break;
case "EADDRINUSE":
console.error(bind + " is already in use");
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port;
debug("Listening on " + bind);
}
23 changes: 23 additions & 0 deletions backend/config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"development": {
"username": "root",
"password": null,
"database": "database_development",
"host": "127.0.0.1",
"dialect": "mysql"
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"username": "root",
"password": null,
"database": "database_production",
"host": "127.0.0.1",
"dialect": "mysql"
}
}
15 changes: 15 additions & 0 deletions backend/middleware/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const authCheck = (req, res, next) => {
console.log(req.user);
if (req.user) {
console.log("success auth");
next();
} else {
console.log("false to auth");
res.status(401).json({
authenticated: false,
message: "user has not been authenticated",
});
}
};

module.exports = { authCheck };
37 changes: 37 additions & 0 deletions backend/models/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.json')[env];
const db = {};

let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}

fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
db[model.name] = model;
});

Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;
Loading