-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
30 lines (23 loc) · 817 Bytes
/
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
const express = require('express')
// import * as express from "express";
const app = express();
const todoRouter = require('./src/routes/todoRoutes');
const userRouter = require('./src/routes/userRoutes')
const connectDB = require('./src/helpers/db');
const cors = require('cors');
const dotenv = require('dotenv');
const path = require('path')
//configure env
dotenv.config();
connectDB();
app.use(cors());
app.use(express.json());
app.use("/todos", todoRouter)
app.use("/user", userRouter)
app.use(express.static(path.join(__dirname, './frontend/todolist/build')))
// for hosting
app.use('*', (req, res) => {
res.sendFile(path.join(__dirname, 'frontend\todolist\build\index.html'))
})
const PORT = process.env.PORT || 8000;
app.listen(PORT, () => console.log(`listening on http://localhost:${PORT}`));