-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (20 loc) · 904 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
require('dotenv').config(); //dotenv config
const express = require('express');
const app = express();
const path = require('path');
const UserRouter = require('./server/routes/user');
const NoteRouter = require('./server/routes/note');
app.use(express.json()); //json bodies
app.use(express.static(__dirname + "/public"));
app.get('/', (req, res) => res.sendFile(path.join(__dirname, "/public/login.html")));
//cors middleware
app.use(function(req, res, next){
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
res.header("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
next();
});
app.use("/users", UserRouter);
app.use("/notes",NoteRouter);
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`server started on port ${PORT}!`));