84 lines
2.7 KiB
JavaScript
84 lines
2.7 KiB
JavaScript
const express = require('express')
|
|
const database = require('./database')
|
|
// global.socket = require("socket.io");
|
|
const fileUpload = require('express-fileupload')
|
|
const {isUser, isAdmin} = require('./authentication')
|
|
const bodyParser = require('body-parser')
|
|
const {removeUser , removeCartItem , birthdateJob , marriageDateJob} = require('./plugins/cronJobs')
|
|
const {createAdmins} = require('./plugins/privateAdmin')
|
|
// global.webPush = require('web-push');
|
|
// const vapidKeys = webPush.generateVAPIDKeys();
|
|
// const StoreInfo = require('./models/StoreInfo')
|
|
// StoreInfo.findOne().then(store => {
|
|
// if (store){
|
|
// global.userRegistrationScore = Number(store.userRegistrationScore)
|
|
// global.userEmailVerifyScore = Number(store.userEmailVerifyScore)
|
|
// global.totalPricePoint = store.totalPricePoint
|
|
// global.pointForBuy = store.pointForBuy
|
|
// global.pricePoint = Math.floor(store.priceForChange/store.pointForChange)
|
|
// global.pointBirthDate = Number(store.pointBirthDate)
|
|
// global.pointMarriageDate = Number(store.pointMarriageDate)
|
|
// global.invitePoint = Number(store.invitePoint)
|
|
// }else {
|
|
// global.userRegistrationScore = 0
|
|
// global.userEmailVerifyScore = 0
|
|
// global.totalPricePoint = 0
|
|
// global.pointForBuy = 0
|
|
// global.pricePoint = 0
|
|
// global.pointBirthDate = 0
|
|
// global.pointMarriageDate = 0
|
|
// global.invitePoint = 0
|
|
// }
|
|
// }).catch(error => {
|
|
// global.userRegistrationScore = 0
|
|
// global.userEmailVerifyScore = 0
|
|
// global.totalPricePoint = 0
|
|
// global.pointForBuy = 0
|
|
// global.pricePoint = 0
|
|
// global.pointBirthDate = 0
|
|
// global.pointMarriageDate = 0
|
|
// global.invitePoint = 0
|
|
// })
|
|
global._ = require('lodash');
|
|
const wss = require('./socket/init')
|
|
|
|
// Create express instnace
|
|
const app = express()
|
|
// removeUser()
|
|
// removeCartItem()
|
|
// createAdmins()
|
|
// birth date job for add point and send sms
|
|
birthdateJob().start()
|
|
// marriage date job for add point and send sms
|
|
marriageDateJob().start()
|
|
// Init body-parser options (inbuilt with express)
|
|
app.use(express.json())
|
|
app.use(express.urlencoded({extended: true}))
|
|
app.use(fileUpload())
|
|
|
|
|
|
// const publicVapidKey = vapidKeys.publicKey;
|
|
// const privateVapidKey = vapidKeys.privateKey;
|
|
//
|
|
// webPush.setVapidDetails('mailto:abedzadehalireza19@gmail.com', publicVapidKey, privateVapidKey);
|
|
|
|
// Require & Import API routes
|
|
const Public = require('./routes/public')
|
|
const admin = require('./routes/admin')
|
|
const auth = require('./routes/auth')
|
|
const user = require('./routes/user')
|
|
|
|
// Use API Routes
|
|
app.use('/public', Public)
|
|
app.use('/auth', auth)
|
|
app.use('/admin', isAdmin, admin)
|
|
app.use('/user', isUser, user)
|
|
|
|
wss()
|
|
|
|
// Export the server middleware
|
|
module.exports = {
|
|
path: '/api',
|
|
handler: app
|
|
}
|