SHARE
TWEET

Untitled

a guest Oct 9th, 2019 142 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var express = require('express');
  2. var path = require('path');
  3. var favicon = require('serve-favicon');
  4. var logger = require('morgan');
  5. var cookieParser = require('cookie-parser');
  6. var bodyParser = require('body-parser');
  7. var flash = require('express-flash');
  8. var session = require('express-session');
  9. var index = require('./routes/index');
  10. var users = require('./routes/users');
  11. var customers = require('./routes/customers');
  12. var expressValidator = require('express-validator');
  13. var methodOverride = require('method-override');
  14.  
  15. var connection  = require('express-myconnection');
  16. var mysql = require('mysql');
  17.  
  18. var app = express();
  19. // view engine setup
  20. app.set('views', path.join(__dirname, 'views'));
  21. app.set('view engine', 'jade');
  22.  
  23. // uncomment after placing your favicon in /public
  24. //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
  25. app.use(logger('dev'));
  26. app.use(bodyParser.json());
  27. app.use(bodyParser.urlencoded({ extended: false }));
  28. app.use(session({
  29.   secret:"secretpass123456",
  30.   resave : true,
  31.   saveUninitialized : true
  32. }));
  33. app.use(flash());
  34. app.use(expressValidator());
  35. app.use(methodOverride(function(req, res){
  36.  if (req.body && typeof req.body == 'object' && '_method' in req.body)
  37.   {
  38.       var method = req.body._method;
  39.       delete req.body._method;
  40.       return method;
  41.     }
  42.   }));
  43.  
  44. app.use(cookieParser());
  45. app.use(express.static(path.join(__dirname, 'public')));
  46.  
  47. /*------------------------------------------
  48.     connection peer, register as middleware
  49.     type koneksi : single,pool and request
  50. -------------------------------------------*/
  51. app.use(
  52.     connection(mysql,{
  53.         host: 'localhost',
  54.         user: 'root', // your mysql user
  55.         password : '', // your mysql password
  56.         port : 3306, //port mysql
  57.         database:'nodejs' // your database name
  58.     },'pool') //or single
  59.  
  60. );
  61.  
  62. app.use('/', index);
  63. app.use('/customers', customers);
  64. app.use('/users', users);
  65.  
  66. // catch 404 and forward to error handler
  67. app.use(function(req, res, next) {
  68.   var err = new Error('Not Found');
  69.   err.status = 404;
  70.   next(err);
  71. });
  72.  
  73. // error handler
  74. app.use(function(err, req, res, next) {
  75.   // set locals, only providing error in development
  76.   res.locals.message = err.message;
  77.   res.locals.error = req.app.get('env') === 'development' ? err : {};
  78.  
  79.   // render the error page
  80.   res.status(err.status || 500);
  81.   res.render('error');
  82. });
  83.  
  84. module.exports = app;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top