deploy vercel1
This commit is contained in:
parent
a279408136
commit
dcb45d1b84
176
backend/app.js
176
backend/app.js
|
@ -1,74 +1,114 @@
|
||||||
const express = require('express');
|
// const express = require('express');
|
||||||
const cors = require('cors');
|
// const cors = require('cors');
|
||||||
const dotenv = require('dotenv');
|
// const dotenv = require('dotenv');
|
||||||
const sequelize = require('./config/database');
|
// const sequelize = require('./config/database');
|
||||||
const path = require('path');
|
// const path = require('path');
|
||||||
const userRoutes = require('./routes/userRoutes');
|
// const userRoutes = require('./routes/userRoutes');
|
||||||
const authRoutes = require('./routes/authRoutes');
|
// const authRoutes = require('./routes/authRoutes');
|
||||||
const gejalaRoutes = require('./routes/gejalaRoute');
|
// const gejalaRoutes = require('./routes/gejalaRoute');
|
||||||
const hamaRoutes = require('./routes/hamaRoutes');
|
// const hamaRoutes = require('./routes/hamaRoutes');
|
||||||
const penyakitRoutes = require('./routes/penyakitRoutes');
|
// const penyakitRoutes = require('./routes/penyakitRoutes');
|
||||||
const ruleRoutes = require('./routes/ruleRoutes');
|
// const ruleRoutes = require('./routes/ruleRoutes');
|
||||||
const ruleHamaRoutes = require('./routes/ruleHamaRoutes');
|
// const ruleHamaRoutes = require('./routes/ruleHamaRoutes');
|
||||||
const diagnosaRoute = require('./routes/diagnosaRoutes');
|
// const diagnosaRoute = require('./routes/diagnosaRoutes');
|
||||||
const historiRoutes = require('./routes/historiRoutes');
|
// const historiRoutes = require('./routes/historiRoutes');
|
||||||
const swaggerDocs = require('./swagger');
|
// const swaggerDocs = require('./swagger');
|
||||||
|
|
||||||
dotenv.config();
|
// dotenv.config();
|
||||||
|
|
||||||
|
// const app = express();
|
||||||
|
|
||||||
|
// app.get("/", (req, res) => {
|
||||||
|
// res.send("Backend API is running 👍");
|
||||||
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
// // Middlewares
|
||||||
|
// app.use(express.json());
|
||||||
|
// app.use(cors());
|
||||||
|
|
||||||
|
// // Serve gambar dari folder image_hama
|
||||||
|
// app.use('/image_hama', express.static(path.join(__dirname, 'image_hama')));
|
||||||
|
// // Serve gambar dari folder image_penyakit
|
||||||
|
// app.use('/image_penyakit', express.static(path.join(__dirname, 'image_penyakit')));
|
||||||
|
|
||||||
|
// // Routes
|
||||||
|
// app.use("/api/users", userRoutes);
|
||||||
|
// app.use("/api/auth", authRoutes);
|
||||||
|
// app.use("/api/gejala", gejalaRoutes);
|
||||||
|
// app.use("/api/hama", hamaRoutes);
|
||||||
|
// app.use("/api/penyakit", penyakitRoutes);
|
||||||
|
// app.use("/api/rules_penyakit", ruleRoutes);
|
||||||
|
// app.use("/api/rules_hama", ruleHamaRoutes);
|
||||||
|
// app.use("/api/diagnosa", diagnosaRoute);
|
||||||
|
// app.use("/api/histori", historiRoutes);
|
||||||
|
|
||||||
|
|
||||||
|
// // Swagger Documentation
|
||||||
|
// swaggerDocs(app); // Setup Swagger UI documentation
|
||||||
|
|
||||||
|
// const PORT = process.env.PORT || 5000;
|
||||||
|
|
||||||
|
// // Database Initialization
|
||||||
|
// const initializeDatabase = async () => {
|
||||||
|
// try {
|
||||||
|
// await sequelize.sync({ force: false });
|
||||||
|
// console.log('Database synced');
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error('Error syncing database:', error);
|
||||||
|
// throw error;
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// // Start Server
|
||||||
|
// initializeDatabase()
|
||||||
|
// .then(() => {
|
||||||
|
// app.listen(PORT, () => {
|
||||||
|
// console.log(`Server running on port ${PORT}`);
|
||||||
|
// console.log(`Swagger UI available at http://localhost:${PORT}/api-sibayam`);
|
||||||
|
// });
|
||||||
|
// })
|
||||||
|
// .catch((error) => {
|
||||||
|
// console.error('Error starting the server:', error);
|
||||||
|
// process.exit(1);
|
||||||
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
const express = require('express');
|
||||||
|
const swaggerUi = require('swagger-ui-express');
|
||||||
|
const swaggerJsDoc = require('swagger-jsdoc');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.get("/", (req, res) => {
|
// Swagger Configuration
|
||||||
res.send("Backend API is running 👍");
|
const swaggerOptions = {
|
||||||
});
|
swaggerDefinition: {
|
||||||
|
openapi: '3.0.0',
|
||||||
|
info: {
|
||||||
// Middlewares
|
title: 'SIBAYAM API',
|
||||||
app.use(express.json());
|
version: '1.0.0',
|
||||||
app.use(cors());
|
description: 'Simple Swagger API Docs for Vercel',
|
||||||
|
},
|
||||||
// Serve gambar dari folder image_hama
|
servers: [
|
||||||
app.use('/image_hama', express.static(path.join(__dirname, 'image_hama')));
|
{
|
||||||
// Serve gambar dari folder image_penyakit
|
url: '/',
|
||||||
app.use('/image_penyakit', express.static(path.join(__dirname, 'image_penyakit')));
|
description: 'Deployed on Vercel',
|
||||||
|
},
|
||||||
// Routes
|
],
|
||||||
app.use("/api/users", userRoutes);
|
},
|
||||||
app.use("/api/auth", authRoutes);
|
apis: [], // Kosongkan jika tidak ada dokumentasi route
|
||||||
app.use("/api/gejala", gejalaRoutes);
|
|
||||||
app.use("/api/hama", hamaRoutes);
|
|
||||||
app.use("/api/penyakit", penyakitRoutes);
|
|
||||||
app.use("/api/rules_penyakit", ruleRoutes);
|
|
||||||
app.use("/api/rules_hama", ruleHamaRoutes);
|
|
||||||
app.use("/api/diagnosa", diagnosaRoute);
|
|
||||||
app.use("/api/histori", historiRoutes);
|
|
||||||
|
|
||||||
|
|
||||||
// Swagger Documentation
|
|
||||||
swaggerDocs(app); // Setup Swagger UI documentation
|
|
||||||
|
|
||||||
const PORT = process.env.PORT || 5000;
|
|
||||||
|
|
||||||
// Database Initialization
|
|
||||||
const initializeDatabase = async () => {
|
|
||||||
try {
|
|
||||||
await sequelize.sync({ force: false });
|
|
||||||
console.log('Database synced');
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error syncing database:', error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Start Server
|
const swaggerDocs = swaggerJsDoc(swaggerOptions);
|
||||||
initializeDatabase()
|
|
||||||
.then(() => {
|
// Route utama
|
||||||
app.listen(PORT, () => {
|
app.get('/', (req, res) => {
|
||||||
console.log(`Server running on port ${PORT}`);
|
res.send('Backend API is running 👍');
|
||||||
console.log(`Swagger UI available at http://localhost:${PORT}/api-sibayam`);
|
});
|
||||||
});
|
|
||||||
})
|
// Swagger route
|
||||||
.catch((error) => {
|
app.use('/api-sibayam', swaggerUi.serve, swaggerUi.setup(swaggerDocs));
|
||||||
console.error('Error starting the server:', error);
|
|
||||||
process.exit(1);
|
// Export agar bisa digunakan oleh Vercel (Wajib)
|
||||||
});
|
module.exports = app;
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
"routes": [
|
"routes": [
|
||||||
{
|
{
|
||||||
"src": "/(.*)",
|
"src": "/(.*)",
|
||||||
"dest": "/"
|
"dest": "/app.js"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue