-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
31 lines (30 loc) · 1007 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
/**
* the first thing we need to do is to create the httpServer that will listen
* to the requests, for that i will use an express app so lets require the
* express package, and create an app
*/
let express = require("express");
let cors = require("cors");
const cookieParser = require("cookie-parser");
/**
* the express package returns afunction that when invoked create the express
* app
*/
let app = express();
app.use(cors());
app.use(express.json());
app.use(cookieParser());
/**
* after creating the app lets now manage our routes, we can put all
* of our routes in this script, but its a best practice to isolate
* the routes into separate scripts.
* so lets create our route script and use it in the app
*/
const auth = require("./routes/auth");
app.use("/auth", auth);
app.all("/", (req, res) => {
return res.redirect("/auth");
});
// now lets assign aport for the app to listen on to
let port = process.env.PORT || 5000;
app.listen(port, console.log(`listening on port ${port}`));