-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (30 loc) · 995 Bytes
/
index.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
import express from "express";
import bodyParser from "body-parser";
import cors from "cors";
import dotenv from "dotenv";
import helmet from "helmet";
import morgan from "morgan";
import { Configuration, OpenAIApi } from "openai";
import openAiRoutes from "./routes/openai.js";
/* CONFIGURATIONS */
dotenv.config();
const app = express();
app.use(express.json());
app.use(helmet());
app.use(helmet.crossOriginResourcePolicy({ policy: "cross-origin" }));
app.use(morgan("common"));
app.use(bodyParser.json({ limit: "30mb", extended: true }));
app.use(bodyParser.urlencoded({ limit: "30mb", extended: true }));
app.use(cors());
/* OPEN AI CONFIGURATION */
const configuration = new Configuration({
apiKey: process.env.OPEN_API_KEY,
});
export const openai = new OpenAIApi(configuration);
/* ROUTES */
app.use("/openai", openAiRoutes);
/* SERVER SETUP */
const PORT = process.env.PORT || 9000;
app.listen(PORT, () => {
console.log(`Example app listening at http://localhost:${PORT}`);
});