Skip to content

Commit

Permalink
code reformatted using prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Codehackerone committed Apr 18, 2022
1 parent 810e6de commit 4a5f21f
Show file tree
Hide file tree
Showing 34 changed files with 8,592 additions and 8,560 deletions.
46 changes: 25 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@
A simple way to solve your complex parking issues.

---

## Requirements

For development, you will only need Node.js and a node global package, npm, installed in your environement.

### Node
- #### Node installation on Windows

Just go on [official Node.js website](https://nodejs.org/) and download the installer.
Also, be sure to have `git` available in your PATH, `npm` might need it (You can find git [here](https://git-scm.com/)).
- #### Node installation on Windows

Just go on [official Node.js website](https://nodejs.org/) and download the installer.
Also, be sure to have `git` available in your PATH, `npm` might need it (You can find git [here](https://git-scm.com/)).

- #### Node installation on Ubuntu
- #### Node installation on Ubuntu

You can install nodejs and npm easily with apt install, just run the following commands.
You can install nodejs and npm easily with apt install, just run the following commands.

$ sudo apt install nodejs
$ sudo apt install npm
$ sudo apt install nodejs
$ sudo apt install npm

- #### Other Operating Systems
You can find more information about the installation on the [official Node.js website](https://nodejs.org/) and the [official NPM website](https://npmjs.org/).
- #### Other Operating Systems
You can find more information about the installation on the [official Node.js website](https://nodejs.org/) and the [official NPM website](https://npmjs.org/).

If the installation was successful, you should be able to run the following command.

Expand All @@ -48,18 +50,20 @@ If you need to update `npm`, you can make it using `npm`! Cool right? After runn
## Configure environmental variables

Create a `.env` file then edit it with your settings. You will need:
- ENV=development
- PORT=[your_port]
- MONGO_URI=[your_mongo_uri]
- JWT_SECRET=[your_jwt_secret]
- EXPIRY=[your_jwt_expiry_time]
- SECRET=[your_secret_for_mongostore]
- EMAIL=[your_email_address]
- PASS=[your_email_password]
- CLOUDINARY_CLOUD_NAME=[your_cloudinary_cloud_name]
- CLOUDINARY_KEY=[your_cloudinary_key]
- CLOUDINARY_SECRET=[your_cloudinary_secret]
- MAPBOX_TOKEN=[your_mapbox_project]

- ENV=development
- PORT=[your_port]
- MONGO_URI=[your_mongo_uri]
- JWT_SECRET=[your_jwt_secret]
- EXPIRY=[your_jwt_expiry_time]
- SECRET=[your_secret_for_mongostore]
- EMAIL=[your_email_address]
- PASS=[your_email_password]
- CLOUDINARY_CLOUD_NAME=[your_cloudinary_cloud_name]
- CLOUDINARY_KEY=[your_cloudinary_key]
- CLOUDINARY_SECRET=[your_cloudinary_secret]
- MAPBOX_TOKEN=[your_mapbox_project]

## Running the project

$ npm start
Expand Down
106 changes: 53 additions & 53 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
/* ------------ Imports ----------- */

const express = require("express");
const cors = require("cors");
const mongoose = require("mongoose");
const cookieParser = require("cookie-parser");
const favicon = require("serve-favicon");
const session = require("express-session");
const MongoDBStore = require("connect-mongo")(session);
const flash = require("express-flash");
const helmet = require("helmet");
const methodOverride = require("method-override");
const express = require('express');
const cors = require('cors');
const mongoose = require('mongoose');
const cookieParser = require('cookie-parser');
const favicon = require('serve-favicon');
const session = require('express-session');
const MongoDBStore = require('connect-mongo')(session);
const flash = require('express-flash');
const helmet = require('helmet');
const methodOverride = require('method-override');

/* ------------ Configs ----------- */

// initialize module to access .env variables
require("dotenv").config();
require('dotenv').config();

// access port from env
const port = Number(process.env.PORT);

// db connection variables
const uri = String(process.env.MONGO_URI);
const connectOptions = {
useNewUrlParser: true, // used for parsing the uri
useCreateIndex: true, // use mongoose's default index
useUnifiedTopology: true, // use the newer topology engine
useFindAndModify: false, // allow findOneAndUpdate()
useNewUrlParser: true, // used for parsing the uri
useCreateIndex: true, // use mongoose's default index
useUnifiedTopology: true, // use the newer topology engine
useFindAndModify: false, // allow findOneAndUpdate()
};

/* ------------ MongoDB Setup ----------- */

// initiate connection to mongodb
mongoose
.connect(uri, connectOptions)
.then()
.catch((err) => console.log("Error:" + err));
.connect(uri, connectOptions)
.then()
.catch((err) => console.log('Error:' + err));

// log message on connection success
mongoose.connection.once("open", () =>
console.log("Connected to MongoDB successfully...")
mongoose.connection.once('open', () =>
console.log('Connected to MongoDB successfully...')
);

const app = express();

const secret = process.env.SECRET;

const store = new MongoDBStore({
url: uri,
secret,
touchAfter: 24 * 60 * 60,
url: uri,
secret,
touchAfter: 24 * 60 * 60,
});

// session initialization
store.on("error", function (e) {
console.log("SESSION STORE ERROR", e);
store.on('error', function (e) {
console.log('SESSION STORE ERROR', e);
});

const sessionConfig = {
store, // session store
name: "session", // session name
secret, // session secret
resave: false, // don't save session if unmodified
saveUninitialized: true, // don't create session until something stored
cookie: {
httpOnly: true, // don't let browser javascript access cookies
expires: Date.now() + 1000 * 60 * 60 * 24 * 7, // expire in 7 days
maxAge: 1000 * 60 * 60 * 24 * 7, // expire in 7 days
},
store, // session store
name: 'session', // session name
secret, // session secret
resave: false, // don't save session if unmodified
saveUninitialized: true, // don't create session until something stored
cookie: {
httpOnly: true, // don't let browser javascript access cookies
expires: Date.now() + 1000 * 60 * 60 * 24 * 7, // expire in 7 days
maxAge: 1000 * 60 * 60 * 24 * 7, // expire in 7 days
},
};

app.use(cors()); // allow cross-origin requests
Expand All @@ -75,41 +75,41 @@ app.use(express.urlencoded({ extended: true })); // parse the incoming requests
app.use(cookieParser()); // parse the incoming requests with cookies
app.use(session(sessionConfig)); // initialize session
app.use(flash()); // initialize flash messages
app.use(methodOverride("_method")); // override HTTP methods
app.use(methodOverride('_method')); // override HTTP methods
app.use(helmet({ contentSecurityPolicy: false }));
app.use(favicon(__dirname + "/public/img/favicon.ico"));
app.use(favicon(__dirname + '/public/img/favicon.ico'));

// use ejs template engine and allow serving static files
app.use(express.static(__dirname + "/public"));
app.set("view engine", "ejs");
app.use(express.static(__dirname + '/public'));
app.set('view engine', 'ejs');

//include routes from /
app.get("/", (req, res) => {
res.render("index");
app.get('/', (req, res) => {
res.render('index');
});

//include routes from /users
const userRouter = require("./routes/user.route");
app.use("/users", userRouter);
const userRouter = require('./routes/user.route');
app.use('/users', userRouter);

//include routes from /garages
const garageRouter = require("./routes/garage.route");
app.use("/garage", garageRouter);
const garageRouter = require('./routes/garage.route');
app.use('/garage', garageRouter);

//include routes from /slots
const slotRouter = require("./routes/slot.route");
app.use("/slot", slotRouter);
const slotRouter = require('./routes/slot.route');
app.use('/slot', slotRouter);

//include routes from /booking
const bookingRouter = require("./routes/booking.route");
app.use("/booking", bookingRouter);
const bookingRouter = require('./routes/booking.route');
app.use('/booking', bookingRouter);

// handle all routes without endpoints
app.get("*", (req, res) => {
res.render("not-found");
app.get('*', (req, res) => {
res.render('not-found');
});

// start the parkify server
app.listen(port, () =>
console.log(`Parkify running at http://localhost:${port}`)
);
console.log(`Parkify running at http://localhost:${port}`)
);
24 changes: 12 additions & 12 deletions cloudinary/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const cloudinary = require("cloudinary").v2;
const { CloudinaryStorage } = require("multer-storage-cloudinary");
const cloudinary = require('cloudinary').v2;
const { CloudinaryStorage } = require('multer-storage-cloudinary');

// cloudinary configuration
cloudinary.config({
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_KEY,
api_secret: process.env.CLOUDINARY_SECRET,
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_KEY,
api_secret: process.env.CLOUDINARY_SECRET,
});

const storage = new CloudinaryStorage({
cloudinary, // Cloudinary instance
params: {
folder: "Parkify", // The name of the folder in cloudinary
allowedFormats: ["jpeg", "png", "jpg"], // The formats you want to allow
},
cloudinary, // Cloudinary instance
params: {
folder: 'Parkify', // The name of the folder in cloudinary
allowedFormats: ['jpeg', 'png', 'jpg'], // The formats you want to allow
},
});

module.exports = {
cloudinary,
storage,
cloudinary,
storage,
};
Loading

0 comments on commit 4a5f21f

Please sign in to comment.