summaryrefslogtreecommitdiffstats
path: root/backend/src/index.js
blob: 6b196f322a4a741d8c8003a4ba8cd57160c74bb4 (plain)
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
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const morgan = require('morgan');
const routes = require('./routes');

const app = express();

app.use((_, res, next) => {
  try {
    next();
  } catch (err) {
    console.error(err);
    res.status(500);
    res.json({
      error: 'Internal server error',
    });
  }
});
app.use(morgan('dev'));
app.use(bodyParser.json());
app.use(cookieParser());
app.use((req, res, next) => {
  res.set('Access-Control-Allow-Origin', 'http://localhost:3000');
  res.set('Access-Control-Allow-Headers', 'Content-Type');
  res.set('Access-Control-Allow-Credentials', true);
  next();
});
app.use(routes.normalRouter);
app.use(routes.authedRouter);

const port = 4000;
app.listen(port, () => console.log(`App listening on http://localhost:${port}!`));