-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
74 lines (64 loc) · 1.79 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const express = require('express')
const app = express()
const bodyParser = require('body-parser')
var cloudinary = require('cloudinary')
const dotenv = require('dotenv')
const Sequelize = require('sequelize')
const seedDB = require('./seed');
dotenv.config()
const nodemailer = require('nodemailer')
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'nurturebot7412',
},
})
const {
DB_NAME,
DB_USERNAME,
DB_PASSWORD,
DB_HOST,
CLOUDINARY_CLOUD_NAME,
CLOUDINARY_API_KEY,
CLOUDINARY_API_SECRET,
} = process.env
const sequelize = new Sequelize(DB_NAME, DB_USERNAME, DB_PASSWORD, {
host: DB_HOST,
dialect: 'mysql',
operatorsAliases: false,
})
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization')
next()
})
cloudinary.config({
cloud_name: CLOUDINARY_CLOUD_NAME,
api_key: CLOUDINARY_API_KEY,
api_secret: CLOUDINARY_API_SECRET,
})
// importing routes
const auth_routes = require('./routes/auth')(sequelize)
const crud_routes = require('./routes/general/crud')(sequelize)
const employee_routes = require('./routes/employee')(sequelize, transporter)
const attendance_routes = require('./routes/attendance')(sequelize, transporter)
app.use(
bodyParser.urlencoded({
extended: true,
})
)
app.use(bodyParser.json())
app.use(auth_routes)
app.use(crud_routes)
app.use('/attendance', attendance_routes);
app.use('/employee', employee_routes)
require('./models/relationships.js')(sequelize)
sequelize.sync({force: true}).then(() => {
const models = require('./models/')(sequelize)
seedDB(models);
})
// middleware for protected routes
app.listen(2200, () => {
console.log('API Server Running.')
})