diff --git a/.gitignore b/.gitignore index afd0003..48d1234 100644 --- a/.gitignore +++ b/.gitignore @@ -50,7 +50,6 @@ node_modules dist .idea application.log -static/files/* cache_temp/* static_temp/* .vscode diff --git a/app.js b/app.js index 9bfb81b..82e472b 100644 --- a/app.js +++ b/app.js @@ -1,12 +1,37 @@ -const express = require('express'); -const logger = require('morgan'); +var createError = require('http-errors'); +var express = require('express'); +var path = require('path'); +var logger = require('morgan'); -const app = express(); +var indexRouter = require('./routes/index'); -app.get('/', (req, res) => { - res.send('Hello CMS!') +var app = express(); + +// 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(express.static(path.join(__dirname, 'public'))); + +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'); }); -app.listen(3000, () => { - console.log('Server started and listening on PORT: 3000'); -}); \ No newline at end of file +module.exports = app; diff --git a/bin/www b/bin/www new file mode 100644 index 0000000..bb00185 --- /dev/null +++ b/bin/www @@ -0,0 +1,90 @@ +#!/usr/bin/env node + +/** + * Module dependencies. + */ + +var app = require('../app'); +var debug = require('debug')('cms-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); +} diff --git a/package.json b/package.json index 8c9bc68..7d0461a 100644 --- a/package.json +++ b/package.json @@ -1,44 +1,15 @@ { - "name": "cms-backend-api", - "version": "1.0.0", - "description": "Simple CMS backend", - "main": "app.js", + "name": "cms-backend", + "version": "0.0.0", + "private": true, "scripts": { - "start": "node app.js", - "test": "mocha" + "start": "node ./bin/www" }, - "author": "Satyajit Dey", - "contributors": [ - { - "name": "Ahmed Maruf", - "email": "maruf@cefalo.com" - }, - { - "name": "Atiqul Alama", - "email": "atiqul@cefalo.com" - }, - { - "name": "Rezaul Karim", - "email": "tito@cefalo.com" - }, - { - "name": "Satyajit Dey", - "email": "satyajit@cefalo.com" - } - ], - "license": "ISC", "dependencies": { - "express": "4.17.1", - "morgan": "1.10.0", - "passport": "0.4.1" - }, - "devDependencies": { - "eslint": "6.8.0", - "mocha": "7.1.2", - "nodemon": "2.0.3" - }, - "repository": { - "type": "git", - "url": "https://github.com/Cefalo/cms-backend-api.git" + "debug": "~2.6.9", + "express": "~4.16.1", + "http-errors": "~1.6.3", + "jade": "~1.11.0", + "morgan": "~1.9.1" } } diff --git a/public/css/style.css b/public/css/style.css new file mode 100644 index 0000000..9453385 --- /dev/null +++ b/public/css/style.css @@ -0,0 +1,8 @@ +body { + padding: 50px; + font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; +} + +a { + color: #00B7FF; +} diff --git a/routes/index.js b/routes/index.js new file mode 100644 index 0000000..78c7694 --- /dev/null +++ b/routes/index.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET home page. */ +router.get('/', function(req, res, next) { + res.render('index', { title: 'Cefalo CMS' }); +}); + +module.exports = router; diff --git a/views/error.jade b/views/error.jade new file mode 100644 index 0000000..2ba2dc2 --- /dev/null +++ b/views/error.jade @@ -0,0 +1,5 @@ +extends layout + +block content + h1 #{error.status} #{message} + pre #{error.stack} diff --git a/views/index.jade b/views/index.jade new file mode 100644 index 0000000..30df784 --- /dev/null +++ b/views/index.jade @@ -0,0 +1,23 @@ +doctype html +html + head + title= title + style(type='text/css'). + html,body{height:100%}body{display: table;margin: 0 auto;font-size:3em;text-align: center}div{text-align:left;display: table-cell;vertical-align: middle} + + body + div + pre + | /~\ + | |oo ) Hello World! + | _\=/_ + | ___ / _ \ + | / ()\ //|/.\|\\ + | _|_____|_ \\ \_/ || + | | | === | | \|\ /| || + | |_| O |_| # _ _/ # + | || O || | | | + | ||__*__|| | | | + | |~ \___/ ~| []|[] + | /=\ /=\ /=\ | | | + |_____[_]_[_]_[_]________/_]_[_\____________ diff --git a/views/layout.jade b/views/layout.jade new file mode 100644 index 0000000..215cbc6 --- /dev/null +++ b/views/layout.jade @@ -0,0 +1,7 @@ +doctype html +html + head + title= title + link(rel='stylesheet', href='/css/style.css') + body + block content