deploy vercel1
This commit is contained in:
parent
dcb45d1b84
commit
1c9815177e
|
@ -75,19 +75,34 @@
|
||||||
|
|
||||||
|
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
|
const cors = require('cors');
|
||||||
|
const path = require('path');
|
||||||
|
const dotenv = require('dotenv');
|
||||||
const swaggerUi = require('swagger-ui-express');
|
const swaggerUi = require('swagger-ui-express');
|
||||||
const swaggerJsDoc = require('swagger-jsdoc');
|
const swaggerJsDoc = require('swagger-jsdoc');
|
||||||
|
|
||||||
|
const userRoutes = require('../routes/userRoutes');
|
||||||
|
const authRoutes = require('../routes/authRoutes');
|
||||||
|
const gejalaRoutes = require('../routes/gejalaRoute');
|
||||||
|
const hamaRoutes = require('../routes/hamaRoutes');
|
||||||
|
const penyakitRoutes = require('../routes/penyakitRoutes');
|
||||||
|
const ruleRoutes = require('../routes/ruleRoutes');
|
||||||
|
const ruleHamaRoutes = require('../routes/ruleHamaRoutes');
|
||||||
|
const diagnosaRoute = require('../routes/diagnosaRoutes');
|
||||||
|
const historiRoutes = require('../routes/historiRoutes');
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
// Swagger Configuration
|
// Swagger config
|
||||||
const swaggerOptions = {
|
const swaggerOptions = {
|
||||||
swaggerDefinition: {
|
swaggerDefinition: {
|
||||||
openapi: '3.0.0',
|
openapi: '3.0.0',
|
||||||
info: {
|
info: {
|
||||||
title: 'SIBAYAM API',
|
title: 'SIBAYAM API',
|
||||||
version: '1.0.0',
|
version: '1.0.0',
|
||||||
description: 'Simple Swagger API Docs for Vercel',
|
description: 'API documentation for SIBAYAM',
|
||||||
},
|
},
|
||||||
servers: [
|
servers: [
|
||||||
{
|
{
|
||||||
|
@ -95,20 +110,48 @@ const swaggerOptions = {
|
||||||
description: 'Deployed on Vercel',
|
description: 'Deployed on Vercel',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
components: {
|
||||||
|
securitySchemes: {
|
||||||
|
BearerAuth: {
|
||||||
|
type: 'http',
|
||||||
|
scheme: 'bearer',
|
||||||
|
bearerFormat: 'JWT',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
apis: [], // Kosongkan jika tidak ada dokumentasi route
|
apis: ['../routes/*.js'],
|
||||||
};
|
};
|
||||||
|
|
||||||
const swaggerDocs = swaggerJsDoc(swaggerOptions);
|
const swaggerDocs = swaggerJsDoc(swaggerOptions);
|
||||||
|
|
||||||
// Route utama
|
// Middleware
|
||||||
|
app.use(cors());
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
|
// Static image folders
|
||||||
|
app.use('/image_hama', express.static(path.join(__dirname, '../image_hama')));
|
||||||
|
app.use('/image_penyakit', express.static(path.join(__dirname, '../image_penyakit')));
|
||||||
|
|
||||||
|
// Routes
|
||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
res.send('Backend API is running 👍');
|
res.send('Backend API is running 👍');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Swagger route
|
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 UI
|
||||||
app.use('/api-sibayam', swaggerUi.serve, swaggerUi.setup(swaggerDocs));
|
app.use('/api-sibayam', swaggerUi.serve, swaggerUi.setup(swaggerDocs));
|
||||||
|
|
||||||
// Export agar bisa digunakan oleh Vercel (Wajib)
|
// Export for Vercel
|
||||||
module.exports = app;
|
module.exports = app;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue