-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (52 loc) · 1.57 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
// server/index.js
import express from 'express';
import mongoose from 'mongoose';
import connectDB from './db/db.js';
import cors from 'cors';
import routes from './Routers/routes.js';
import bodyParser from 'body-parser';
const app = express();
app.use(express.json())
app.use(cors());
const __dirname = process.cwd();
app.use(express.static(__dirname + '/public'));
app.get('/', (_, res) => {
res.render('index.html');
});
app.get('/trivia', (_, res) => {
res.sendFile(__dirname + '/public/trivia.html');
});
app.get('/pokemon', (_, res) => {
res.sendFile(__dirname + '/public/pokemon.html');
});
app.get('/leaderboard', (_, res) => {
res.sendFile(__dirname + '/public/leaderboard.html');
});
app.get('/about', (_, res) => {
res.sendFile(__dirname + '/public/about.html');
});
app.get('/contact', (_, res) => {
res.sendFile(__dirname + '/public/contact.html');
});
app.get('/login', (_, res) => {
res.sendFile(__dirname + '/public/login.html');
});
app.get('/signup', (_, res) => {
res.sendFile(__dirname + '/public/signup.html');
});
app.use("/api",routes)
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Define mongoose schema and models, handle routes, etc.
// Start the server
const URL = 'mongodb+srv://admin:[email protected]/QuizApp?retryWrites=true&w=majority'
const port = process.env.PORT || 3000
const start = async ()=>{
try {
await connectDB(URL)
app.listen(port, console.log('Connected to database and server has started'))
} catch (error) {
console.log(error)
}
}
start()