- Express
- Cors
- Cookie-parser
const express = require('express');
const cookieParser = require('cookie-parser');
const cors = require('cors');
require('dotenv').config();
const app = express();
app.use(express.json());
app.use(express.urlencoded({extended: false}));
app.use(cookieParser());
app.use(cors({
origin: [ 'http://localhost:3000'],
methods: ['OPTIONS','GET','POST','PUT','DELETE'],
credentials: true
}));
const usersRouter = require('./routes/users');
const postsRouter = require('./routes/posts');
const commentsRouter = require('./routes/comments');
app.use('/users', usersRouter);
app.use('/posts', postsRouter);
app.use('/comments', commentsRouter);
app.get('/', (req, res) => {
res.redirect('/posts/read');
});
const port = process.env.baseUrl_port;
const baseUrl = process.env.baseUrl || localhost;
app.listen(port, () => {
console.log(`App is running at http://${baseUrl}:${port}`);
});