-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserver.js
53 lines (45 loc) · 1.39 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
const cors = require('cors');
const express = require('express');
const swaggerUi = require('swagger-ui-express');
const swaggerJSDoc = require('swagger-jsdoc');
require('dotenv').config();
const app = express();
const PORT = process.env.PORT || 4400;
app.use(cors())
// Swagger configuration
const swaggerOptions = {
definition: {
openapi: '3.0.0',
info: {
title: 'sb-nodejs-openai',
version: '1.0.0',
description: 'Documentation for RESTful APIs',
contact: {
name: 'RAJESH K',
url: 'https://github.com/rajeshkumaravel',
},
license: {
name: 'Licensed Under MIT',
url: 'https://github.com/rajeshkumaravel/sb-nodejs-openai/blob/main/LICENSE',
},
},
servers: [
{
url: `http://localhost:${PORT}`,
description: 'Development server',
},
],
},
apis: ['./*.js'],
};
const swaggerSpec = swaggerJSDoc(swaggerOptions);
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
app.use(express.json());
// Routes
const apiRoutes = require('./api');
app.use('/api', apiRoutes);
app.listen(PORT, () => {
if (!process.env['OPENAI_API_KEY']) throw new Error('Uh oh, Open AI key is not configured');
if (!process.env['DEFAULT_MODEL']) throw new Error('Uh oh, Default model is not configured');
console.log(`Server is running on port ${PORT}`);
});