Skip to content

Commit

Permalink
v.1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AH Vahedi committed Dec 20, 2020
1 parent 893b5c4 commit c935d21
Show file tree
Hide file tree
Showing 15 changed files with 306 additions and 471 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,5 @@ dist
Version
tmp
.vscode
mongodb.txt
mongodb.txt
_public
15 changes: 10 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ const path = require("path");
const cookieParser = require("cookie-parser");
const moment = require("jalali-moment");
const logger = require("morgan");
const { Server } = require("socket.io");
//Db Config
require("./config/db")();
//App
const app = express();
//Server Config
const server = require("http").createServer(app);
const io = new Server(server);
//Router
const indexRouter = require("./routes/index");
const usersRouter = require("./routes/users");
const deadsRouter = require("./routes/deads");
const apiDeadsRouter = require("./routes/api/apiDeads");
const apiDeadsRouter = require("./routes/api/apiDeads")(io);
const statesRouter = require("./routes/states");
const apiStatesRouter = require("./routes/api/apiStates");
const deadtypesRouter = require("./routes/deadtype");
const costsRouter = require("./routes/costs");
const reportsRouter = require("./routes/reports");
const statementRouter = require("./routes/statements");
//App
const app = express();

const apiStatementRouter = require("./routes/api/apiStatements")(io);
// view engine setup
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "vash");
Expand Down Expand Up @@ -48,6 +52,7 @@ app.use("/deadtypes", deadtypesRouter);
app.use("/costs", costsRouter);
app.use("/reports", reportsRouter);
app.use("/statements", statementRouter);
app.use("/api/statements", apiStatementRouter);
//

// catch 404 and forward to error handler
Expand All @@ -62,4 +67,4 @@ app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.render("error");
});
module.exports = app;
module.exports = { app: app, server: server };
45 changes: 14 additions & 31 deletions bin/www
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

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

const { app, server } = require("../app");
const debug = require("debug")("node:server");
/**
* Get port from environment and store in Express.
*/

const port = normalizePort(process.env.PORT || '80');
app.set('port', port);

/**
* Create HTTP server.
*/

const server = http.createServer(app);
const port = normalizePort(process.env.PORT || "80");
app.set("port", port);

/**
* Listen on provided port, on all network interfaces.
*/
server.timeout = 1200000;
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
server.on("error", onError);
server.on("listening", onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
const port = parseInt(val, 10);

Expand All @@ -54,22 +41,20 @@ function normalizePort(val) {
*/

function onError(error) {
if (error.syscall !== 'listen') {
if (error.syscall !== "listen") {
throw error;
}

const bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
const 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');
case "EACCES":
console.error(bind + " requires elevated privileges");
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
case "EADDRINUSE":
console.error(bind + " is already in use");
process.exit(1);
break;
default:
Expand All @@ -83,8 +68,6 @@ function onError(error) {

function onListening() {
const addr = server.address();
const bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
const bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port;
debug("Listening on " + bind);
}
21 changes: 11 additions & 10 deletions config/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ const mongoose = require("mongoose");
// const url = "";
const url = "mongodb://localhost:27017/Aramestan";

const InitiateMongoServer = async() => {
try {
await mongoose.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true
});
} catch (e) {
throw e;
}
const InitiateMongoServer = async () => {
try {
await mongoose.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false,
});
} catch (e) {
throw e;
}
};
module.exports = InitiateMongoServer;
module.exports = InitiateMongoServer;
22 changes: 22 additions & 0 deletions model/Statements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const mongoose = require("mongoose");

const Statement = mongoose.model(
"C_Statements",
new mongoose.Schema({
NationalId: {
type: String,
required: true,
unique: true,
},
Date: {
type: Date,
default: new Date(),
},
ImageName: {
type: String,
default: "",
},
})
);

module.exports = Statement;
Loading

0 comments on commit c935d21

Please sign in to comment.