forked from farelamo/Puspresnas-Vokasi-UB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
152 lines (137 loc) · 4.16 KB
/
app.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
const express = require('express')
const session = require('express-session')
const upload = require("express-fileupload");
const bodyparser = require('body-parser')
//const helmet = require('helmet')
// const cors = require("cors");
const app = express()
//SWAGGER
const swaggerUi = require('swagger-ui-express')
const apiDocumentation = require('./apidocs.json')
app.use('/api-docs',swaggerUi.serve, swaggerUi.setup(apiDocumentation))
//END SWAGGER
//Middleware
app.use(express.static('public'));
app.use(express.urlencoded({extended: false}));
app.use(bodyparser.urlencoded({extended: true}));
app.use(session({secret: 'excalibur'}));
app.use(upload());
app.set('view engine','ejs');
var sess;
//END Middleware
//Routers ADMIN
const dashboard = require('./routers/dashboard')
const user = require('./routers/user')
const bidangLomba = require('./routers/bidangLomba')
const jenisLomba = require('./routers/jenisLomba')
const editJenis = require('./routers/editJenis')
const editBidang = require('./routers/editBidang')
const lombaCat = require('./routers/lombaCat')
const lombaTag = require('./routers/lombaTag')
const lombaAll = require('./routers/lombaAll')
const bidangAll = require('./routers/bidangAll')
const profil = require('./routers/profil')
const login = require('./routers/login')
const index = require('./routers/index')
const artikel = require('./routers/artikel')
const artikelNew = require('./routers/artikelNew')
const artikelEdit = require('./routers/artikelEdit')
const berita = require('./routers/berita')
const beritaNew = require('./routers/beritaNew')
const beritaEdit = require('./routers/beritaEdit')
const kontenCat = require('./routers/kontenCat')
const mahasiswa = require('./routers/mahasiswa')
const mahasiswaNew = require('./routers/mahasiswaNew')
const mahasiswaEdit = require('./routers/mahasiswaEdit')
//END ROUTERS ADMIN
//ROUTERS API
const artikelAPI = require('./API/routersAPI/artikelAPI')
const beritaAPI = require('./API/routersAPI/beritaAPI')
const jenisLombaAPI = require('./API/routersAPI/jenisLombaAPI')
const bidangLombaAPI = require('./API/routersAPI/bidangLombaAPI')
const kategoriKontenAPI = require('./API/routersAPI/kategoriKontenAPI')
const kategoriLombaAPI = require('./API/routersAPI/kategoriLombaAPI')
const tagAPI = require('./API/routersAPI/tagAPI')
const tagLombaAPI = require('./API/routersAPI/tagLombaAPI')
const mahasiswaAPI = require('./API/routersAPI/mahasiswaAPI')
//END ROUTERS API
//PERSAMAAN MIGRATE
//const db = require('./models')
// db.sequelize.sync();
//SECURITY APP
//app.use(helmet())
//CORS
// let whiteList = [
// 'http://localhost:3000',
// 'http://localhost:8000',
// 'https://front-end-simapres.vercel.app/prestasi'
// ];
// let corsOptions = {
// origin: function (origin, callback) {
// if (whiteList.indexOf(origin) !== -1 || !origin) {
// callback(null, true)
// } else {
// callback(new Error('Not allowed by CORS'))
// }
// }
// };
let whiteList = [
'http://localhost:3000',
'http://localhost:8000'
];
let corsOptions = {
origin: function (origin, callback) {
if (whiteList.indexOf(origin) !== -1 || !origin) {
callback(null, true)
} else {
callback(new Error('Not allowed by CORS'))
}
}
};
// app.use(cors(corsOptions));
//END CORS
//ADMIN DASHBOARD
app.use(index)
app.use(login)
app.use(profil)
app.use(dashboard)
app.use(artikel)
app.use(artikelNew)
app.use(artikelEdit)
app.use(berita)
app.use(beritaNew)
app.use(beritaEdit)
app.use(kontenCat)
app.use(jenisLomba)
app.use(bidangLomba)
app.use(bidangAll)
app.use(editJenis)
app.use(editBidang)
app.use(lombaAll)
app.use(lombaCat)
app.use(lombaTag)
app.use(user)
app.use(mahasiswa)
app.use(mahasiswaNew)
app.use(mahasiswaEdit)
//END ADMIN DASHBOARD
//API
app.use(artikelAPI)
app.use(beritaAPI)
app.use(bidangLombaAPI)
app.use(jenisLombaAPI)
app.use(kategoriKontenAPI)
app.use(kategoriLombaAPI)
app.use(tagAPI)
app.use(tagLombaAPI)
app.use(mahasiswaAPI)
//END API
app.get('/logout', (req, res) => {
sess=req.session;
sess.id_user=undefined;
res.redirect('/login');
})
//CONFIGURASI SERVER LOCAL
app.listen(3000, ()=> {
console.log('server listening on port 3000...')
})