-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
59 lines (42 loc) · 1.67 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
import express from "express";
import dotenv from 'dotenv';
import bodyParser from "body-parser";
import path from "path";
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename)
import connectDB from "./sourceFiles/connectdb.js";
import RegisterFile from "./sourceFiles/register.js";
import LoginFile from "./sourceFiles/login.js";
import AddTeacherFile from "./sourceFiles/addteacher.js"
import AddSubjectFile from "./sourceFiles/addSubject.js";
import AddFlotFormsFile from "./sourceFiles/floatforms.js";
import GetFormDataFile from "./sourceFiles/getFormData.js";
import GetSubjectsFile from "./sourceFiles/getSubjects.js";
import GetSaveFormDataFile from "./sourceFiles/saveformdata.js";
import GetFormResultsFile from "./sourceFiles/sendFormResults.js";
var app = express();
app.use(bodyParser.urlencoded({extended: true}));
dotenv.config();
connectDB();
app.use("/register", RegisterFile);
app.use("/login", LoginFile);
app.use("/addteacher", AddTeacherFile);
app.use("/addsubject", AddSubjectFile);
app.use("/floatforms", AddFlotFormsFile);
app.use("/getformdata", GetFormDataFile);
app.use("/getsubjects", GetSubjectsFile);
app.use("/saveformdata", GetSaveFormDataFile);
app.use("/getformresults", GetFormResultsFile);
if(process.env.NODE_ENV === 'production'){
app.use(express.static("frontend/build"));
app.get("*", (req,res) =>{
res.sendFile(path.resolve(__dirname,'frontend','build',
'index.html'));
})
}
console.log(process.env.PORT);
var PORT = process.env.PORT || 8000;
app.listen(PORT, ()=>{
console.log("backend running at port " + PORT);
})