-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
60 lines (46 loc) · 1.44 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
54
55
56
57
58
59
// import express from 'express';
// import * as url from 'url';
// const __filename = url.fileURLToPath(import.meta.url);
// const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
const express = require('express');
// import Connection from './database/db.js';
// import DefaultData from './default.js';
// import Route from './routes/route.js';
const Route = require('./routes/route.js');
// import cors from 'cors';
const cors = require('cors');
// import dotenv from 'dotenv';
const dotenv = require('dotenv');
// import path from 'path';
const path = require('path');
const app = express();
dotenv.config();
app.use(cors());
app.use('/',Route);
const PORT = process.env.PORT || 8000;
// const username = process.env.DB_USERNAME;
// const password = process.env.DB_PASSWORD;
// if(process.env.NODE_ENV === 'production')
// {
// app.use(express.static("client/build"));
// }
// else
// {
// app.use(express.static(path.join(__dirname, "./client/build")));
// app.get("*", function (_, res) {
// res.sendFile(
// path.join(__dirname, "./client/build/index.html"),
// function (err) {
// res.status(500).send(err);
// }
// );
// });
// }
//static files
app.use(express.static(path.join(__dirname, "./client/build")));
app.get("*", function (req, res) {
res.sendFile(path.join(__dirname, "./client/build/index.html"));
});
app.listen(PORT,()=>{
console.log(`Server Started SuccessFully on PORT ${PORT}`);
});