const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');

const cors = require('cors')

const indexRouter = require('./routes/index');
const categoryRouter = require('./routes/category');
const newsRouter = require('./routes/news');
const contactRouter = require('./routes/contact');
const testRouter = require('./routes/test');

//文章路由文件
const adminArticlesRouter = require('./routes/admin/articles');

const app = express();

//cors 跨域配置
const corsOptions = {
    origin:[
        'https://site-api.feiniaotech.com',
        'http://localhost:3000'
    ]
}
// app.use(cors(corsOptions));
app.use(cors());

app.use(logger('dev'));
// 增加请求体大小限制以支持富文本内容
app.use(express.json({ limit: '50mb' }));
app.use(express.urlencoded({ extended: false, limit: '50mb' }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);

//文章路由文件
app.use('/admin/articles', adminArticlesRouter);
app.use('/category', categoryRouter);
app.use('/news', newsRouter);
app.use('/contact', contactRouter);
app.use('/test', testRouter);

module.exports = app;
