-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (65 loc) · 2.08 KB
/
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
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
63
64
65
66
67
68
69
70
71
72
import express from "express";
import bodyParser from "body-parser";
import mongoose from "mongoose";
import { createClient } from "@supabase/supabase-js";
import cors from "cors";
import dotenv from "dotenv";
import helmet from "helmet";
import morgan from "morgan";
import gamesRoutes from "./routes/games.js";
import geographyRoutes from "./routes/geography.js";
import calendarRoutes from "./routes/calendar.js";
import movesRoutes from "./routes/moves.js";
// import managementRoutes from "./routes/management.js";
// import salesRoutes from "./routes/sales.js";
// data imports
// import Game from "./models/Game.js";
// import GameStageInfo from "./models/GameStageInfo.js";
// import GameMovesInfo from "./models/GameMovesInfo.js";
// import {
// dataGames,
// // dataGameMovesInfo,
// dataGameStageInfo,
// } from "./data/index.js";
/* CONFIGURATION */
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());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cors());
/* ROUTES */
app.use("/games", gamesRoutes);
app.use("/geography", geographyRoutes);
app.use("/calendar", calendarRoutes);
app.use("/moves", movesRoutes);
/* SUPABASE SETUP */
const supabase = createClient(
process.env.SUPABASE_URL,
process.env.SUPABASE_KEY
);
// let { data, error } = await supabase.rpc("getTotalGames", {
// enddate: "2024-01-01",
// startdate: "2014-01-01",
// timeclass: "Bullet",
// });
// if (error) console.error(error);
// else console.log(data);
/* MONGOOSE SETUP */
const PORT = process.env.SERVER_PORT || 9000;
mongoose
.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
app.listen(PORT, () => console.log(`Server Port: ${PORT}`));
/* ONLY ADD DATA ONE TIME */
// Game.insertMany(dataGames);
// GameStageInfo.insertMany(dataGameStageInfo);
// GameMovesInfo.insertMany(dataGameMovesInfo);
})
.catch((error) => console.error(`${error} did not connect.`));