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

deploy ch 10 #70

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .env copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DB_HOST =
DB_PORT =
DB_NAME =
DB_USER =
DB_PASS =
SECRET_LOGIN =
SECRET_NAME =
61 changes: 61 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,62 @@
node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
61 changes: 61 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var session = require('express-session');
var flash = require('express-flash')

var cors = require('cors');

var indexRouter = require('./routes/index');

var passport = require('./lib/passport')

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

app.use(cors());

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')));

// session
app.use(session({
secret: process.env.SECRET_NAME,
resave: false,
saveUninitialized: false,
}))

// passport
app.use(passport.initialize())
app.use(passport.session())

// flash
app.use(flash())

app.use('/', indexRouter);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
});

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

/**
* Module dependencies.
*/

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

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

var port = normalizePort(process.env.PORT || '5000');
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

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

server.listen(port, () => {
console.log(`Server listening on PORT ${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);
}
15 changes: 15 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// PANGGIL SEQUELIZE NYA
const { Sequelize } = require('sequelize')

// BIKIN VARIABEL UNTUK NYIMPAN CONFIG SEQUELIZE NYA
const sequelize = new Sequelize({
database: process.env.DB_NAME,
host: process.env.DB_HOST,
port: process.env.DB_PORT,
username: process.env.DB_USER,
password: process.env.DB_PASS,
dialect: 'postgres'
})

// EXPORTS VARIABEL SEQUELIZE NYA
module.exports = { sequelize }
35 changes: 35 additions & 0 deletions controllers/GameController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// import models
const { gameListModel } = require('../models/gameListModel');
const { historyUser } = require('../models/history');

class GameController {
//controller untuk melihat gameList
static async getGameList(req, res) {
try {
// ambil semua data game dari model
const gameList = await gameListModel.getGameList();
// kirim semua data ke user
return res.json({ status: 'success', data: gameList });
} catch (error) {
console.log(error);
res.status(500).send(' Internal Server Error !');
}
}

// controller to insert game score
static async insertRPSscore(req, res) {
try {
console.log(req.body)
const data = req.body;
const user_id = Number(data.user_id);
const user_skor = Number(data.skor);
await historyUser.insertScore(user_id, user_skor);
return res.json({ status: 'success', message: "Score updated!" });
} catch (error) {
console.log(error);
return res.status(500).send(' Internal Server Error !');
}
}
}

module.exports = { GameController }
86 changes: 86 additions & 0 deletions controllers/LandingPageController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// import models
const { LandingPageModel } = require('../models/landingPage')
const { gameListModel } = require('../models/gameListModel');

class LandingPageController {

// get list of community
static async playerCommunity(req, res) {
try {
// get all data related with user
const communityList = await LandingPageModel.getUserData();

// send data
return res.json({ status: 'success', data: communityList });

} catch (error) {
console.log(error);
res.status(500).json({ status: 'failed', data: [] });
}
}


// get list of leaderboard
static async playerLeaderboard(req, res) {
try {
// get all data related with user
const leaderboardList = await LandingPageModel.getUserData();

// send data, take only top 5 users
return res.json({ status: 'success', data: leaderboardList.slice(0, 5) });

} catch (error) {
console.log(error);
res.status(500).json({ status: 'failed', data: [] });
}
}


// get list of trending games for carousel
static async trendingGames(req, res) {
try {
// get all data related with user
const trendingGameList = await gameListModel.getTrendingGameList();

// send data
return res.json({ status: 'success', data: trendingGameList });

} catch (error) {
console.log(error);
res.status(500).json({ status: 'failed', data: [] });
}
}


// get list of popular games for landing page
static async popularGames(req, res) {
try {
// get all data related with user
const popularGameList = await gameListModel.getPopularGameList();

// send data
return res.json({ status: 'success', data: popularGameList });

} catch (error) {
console.log(error);
res.status(500).json({ status: 'failed', data: [] });
}
}

// get list of coming soon games for component
static async comingSoonGames(req, res) {
try {
// get all data related with user
const comingSoonGameList = await gameListModel.getComingSoonGameList();

// send data
return res.json({ status: 'success', data: comingSoonGameList });

} catch (error) {
console.log(error);
res.status(500).json({ status: 'failed', data: [] });
}
}
}

module.exports = { LandingPageController }
Loading