-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
62 lines (47 loc) · 1.64 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
const express = require('express');
const cors = require('cors');
const app = express();
const port = process.env.PORT || 3000;
const path = require('path');
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/config/config.js')[env];
const corsOptions = {
origin: [
'https://techfuture.my.id',
'https://adminnagariintern-0e7da3590c83.herokuapp.com',
'http://localhost:3000',
'http://localhost:5173',
'http://localhost:5000',
'http://localhost:5001',
],
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization', 'x-access-token'],
credentials: true,
optionsSuccessStatus: 200
};
// Use CORS middleware with options
app.use(cors(corsOptions));
const indexRouter = require("./routes/intern");
const authRouter = require("./routes/auth");
const proxyRouter = require("./routes/proxy");
const superadminRouter = require("./routes/superAdmin");
const adminRouter = require("./routes/adminCabang");
// Middleware to parse JSON bodies
app.use(express.json());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'public/template'));
app.get('/', (req, res) => {
res.send('Hello, Express!');
});
// API routes
app.use("/", indexRouter);
app.use("/auth", authRouter);
app.use("/api", proxyRouter);
app.use("/admin", adminRouter);
app.use("/superadmin", superadminRouter);
// Start the server
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});