var createError = require('http-errors'); var express = require('express'); var path = require('path'); var cookieParser = require('cookie-parser'); var logger = require('morgan'); const http = require('http'); const https = require('https'); const fs = require('fs'); const hostname = 'petrov.nexus'; const httpPort = 4080; //const httpsPort = 443; // const httpsOptions = { // key: fs.readFileSync('./archive/server.key'), // cert: fs.readFileSync('./archive/petrov_nexus.crt'), // ca: fs.readFileSync('./archive/petrov_nexus.ca-bundle') // }; // vključimo mongoose in ga povežemo z MongoDB var mongoose = require('mongoose'); var mongoDB = "mongodb://127.0.0.1/my_database"; mongoose.connect(mongoDB); mongoose.set('strictQuery', false); mongoose.Promise = global.Promise; var db = mongoose.connection; db.on('error', console.error.bind(console, 'MongoDB connection error:')); var app = express(); const httpServer = http.createServer(app); //const httpsServer = https.createServer(httpsOptions, app); // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'hbs'); 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'))); var mainRouter = require('./routes/main'); var listRouter = require('./routes/list'); var apiRouter = require('./routes/api/apiRouter'); var mailRouter = require('./routes/mail'); //var userRouter = require('./routes/user'); app.use('/', mainRouter); app.use('/list', listRouter); app.use('/api', apiRouter); app.use('/mail', mailRouter); //app.use('/user', userRouter); // 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', { title: 'Error' }); }); httpServer.listen(httpPort, () => { console.log(`Server running at http://${hostname}:${httpPort}/`); }); // httpsServer.listen(httpsPort, () => { // console.log(`Server running at https://${hostname}:${httpsPort}/`); // }); module.exports = app;