-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e069a2a
commit fc341dc
Showing
19 changed files
with
1,562 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# 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 (http://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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
# hacktivpress | ||
phase 2 the livecode the finale | ||
|
||
Deskripsi dari program yang kita buat | ||
Simple blog tentang sport | ||
|
||
Langkah-langkah yang perlu dijalankan untuk menjalankan program tersebut, | ||
|
||
Serta daftar API Endpoint yang bisa diakses untuk mengambil data. | ||
http://localhost/users/login = login | ||
http://localhost/users/register = register | ||
http://localhost/articles = get all data | ||
http://localhost/articles/add = create data | ||
http://localhost/articles/:id = get one data | ||
http://localhost/articles/update/:id = update data | ||
http://localhost/articles/delete/:id = remove data | ||
http://localhost/articles/author/:id = get by author | ||
http://localhost/articles/category/:id = get by category |
Submodule client
added at
f22e55
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
var createError = require('http-errors'); | ||
var express = require('express'); | ||
var path = require('path'); | ||
var cookieParser = require('cookie-parser'); | ||
var logger = require('morgan'); | ||
const mongoose = require('mongoose') | ||
const cors = require('cors') | ||
var indexRouter = require('./routes/index'); | ||
var usersRouter = require('./routes/users'); | ||
var articlesRouter = require('./routes/articles'); | ||
require('dotenv').config() | ||
|
||
mongoose.connect(`mongodb://ekidb:[email protected]:39198/db_hacktivepress`, ()=>{ | ||
console.log('connect db'); | ||
}) | ||
var app = express(); | ||
app.use(cors()) | ||
// view engine setup | ||
app.set('views', path.join(__dirname, 'views')); | ||
app.set('view engine', 'jade'); | ||
|
||
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('/', indexRouter); | ||
app.use('/users', usersRouter); | ||
app.use('/articles', articlesRouter); | ||
|
||
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/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 || '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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
const Article = require('../models/article.model') | ||
const jwt = require('jsonwebtoken') | ||
|
||
module.exports = { | ||
getAll (req, res) { | ||
Article.find() | ||
.sort([['createdAt', -1]]) | ||
.exec() | ||
.then(response => { | ||
res.status(200).json({ | ||
message: 'query get all articles success', | ||
data: response | ||
}) | ||
}).catch(err => { | ||
res.status(500).json({ | ||
message: 'query get all articles failed', | ||
err | ||
}) | ||
}) | ||
}, | ||
getOne (req, res) { | ||
Article.findById(req.params.id).exec().then(response => { | ||
res.status(200).json({ | ||
message: 'success get data by id', | ||
data: response | ||
}) | ||
}).catch(err => { | ||
res.status(500).json({ | ||
message: 'get data by id failed', | ||
err | ||
}) | ||
}) | ||
}, | ||
|
||
add(req, res) { | ||
console.log('asuippp serverrrr'+req.body.title); | ||
|
||
let title = req.body.title | ||
let content = req.body.content | ||
let category = req.body.category | ||
let userId = req.decoded.id | ||
let newArticle = new Article({ | ||
title: title, | ||
content: content, | ||
category: category, | ||
userId: userId | ||
}) | ||
|
||
newArticle.save().then(response => { | ||
res.status(200).json({ | ||
message: 'query add article success', | ||
data: response | ||
}) | ||
}).catch(err => { | ||
message: 'query add article failed', | ||
err | ||
|
||
}) | ||
}, | ||
|
||
update (req, res) { | ||
let id = req.params.id | ||
let title = req.body.title | ||
let content = req.body.content | ||
let category = req.body.category | ||
let userId = req.decoded.id | ||
|
||
Article.update({ _id: id }, { | ||
$set: { title: title, content: content, category: category, userId:userId}, | ||
|
||
}).then(response => { | ||
res.status(200).json({ | ||
message: 'query update article success', | ||
data: response | ||
}) | ||
}).catch(err => { | ||
message: 'query update article failed', | ||
err | ||
}) | ||
}, | ||
|
||
remove (req, res) { | ||
let id = req.params.id | ||
Article.findByIdAndRemove(id) | ||
.then(response => { | ||
res.status(200).json({ | ||
message: 'query delete article success', | ||
data: response | ||
}) | ||
}).catch(err => { | ||
message: 'query delete article success', | ||
err | ||
}) | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.