import path from 'path';
import express from 'express';
import morgan from 'morgan';
import cookieParser from 'cookie-parser';
import usersRouter from './routes/Users';
import artworksRouter from './routes/Artworks';

const app = express();

app.use(morgan('dev'));
app.use(express.static(path.resolve('..', 'frontend', 'dist')));
app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.use(cookieParser());

app.use('/api/users', usersRouter);
app.use('/api/artworks', artworksRouter);
app.get('/', (req, res) => {
  res.sendFile(path.resolve('..', 'frontend', 'dist', 'index.html'));
});

export default app;
