{"size": 1227, "ext": "js", "max_stars_repo_path": "src/index.js", "max_stars_repo_name": "jsbuddy/automart", "max_stars_repo_stars_event_min_datetime": "2019-06-07T14:41:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T11:00:20.000Z", "max_issues_repo_path": "src/index.js", "max_issues_repo_name": "jsbuddy/automart", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/index.js", "max_forks_repo_name": "jsbuddy/automart", "max_forks_repo_forks_event_min_datetime": "2019-05-17T21:55:28.000Z", "max_forks_repo_forks_event_max_datetime": "2019-05-17T21:55:28.000Z"}
{"max_stars_count": 5, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 26.1063829787, "max_line_length": 105, "alphanum_fraction": 0.6381418093}
import express from 'express';
import morgan from 'morgan';
import cors from 'cors';
import path from 'path';
import api from './api';
import { transform } from './middlewares';
import debug from './lib/debug';

const app = express();
const port = process.env.PORT || 2999;
const dev = app.get('env') !== 'production';

app.use(express.urlencoded({ extended: false }));
app.use(express.json());

app.use(cors({ origin: '*' }));
if (dev) {
  app.use(morgan('dev'));
} else {
  app.use(morgan('common'));
}

app.use(transform);

app.use('/api', api);

app.use(express.static(path.resolve(__dirname, '../ui')));
app.get('/ui', (req, res) => res.sendFile(path.resolve(__dirname, 'build', '../ui/index.html')));

app.all('*', (req, res) => res.status(404).json({ success: false, error: 'Unknown resource endpoint' }));

app.use((err, req, res, next) => {
  if (err.isBoom) {
    debug.error(err.data[0].message);
    return res.status(err.output.statusCode).json({
      status: err.output.statusCode, error: err.data[0].message,
    });
  }
  return next(err);
});

app.use((err, req, res) => res.status(500).json({ status: 500, error: err }));

app.listen(port, () => debug.log(`Listening on port ${port}`));

export default app;
