-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
36 lines (27 loc) · 1009 Bytes
/
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
import express from "express";
import mongoose from "mongoose";
import dotenv from "dotenv";
dotenv.config();
import connectDb from "./config/db.js";
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import path from 'path';
//routes
import authRouter from "./routes/userRoutes.js";
import tasksRouter from "./routes/taskRoutes.js";
import authenticateUser from "./middleware/authMiddleware.js";
const app = express();
const __dirname = dirname(fileURLToPath(import.meta.url));
app.use(express.static(path.resolve(__dirname, './client/build')));
//db connection
mongoose.set("strictQuery", true);
connectDb();
// middleware
app.use(express.json());
app.use("/api/v1/auth", authRouter);
app.use("/api/v1/tasks", authenticateUser, tasksRouter);
app.get('*', function (request, response) {
response.sendFile(path.resolve(__dirname, './client/build', 'index.html'));
});
const port = process.env.PORT || 8000;
app.listen(port, () => console.log(`Server is running on ${port}`));