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 usersRouter = require('./routes/users');

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

const app = express();

//cors 跨域配置
const corsOptions = {
    origin:[
        'https://clwy.cn',
        'http://localhost:3000'
    ]
}
app.use(cors(corsOptions));
// app.use(cors());

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/users', usersRouter);

//文章路由文件
app.use('/admin/articles', adminArticlesRouter);

module.exports = app;
