const express = require('express'); const bodyParser = require('body-parser'); const session = require('express-session'); const path = require('path'); const app = express(); const captcha = require('./routes/captcha'); const signup = require('./routes/signup'); const signin = require('./routes/signin'); const signout = require('./routes/signout'); const index = require('./routes/index'); const userList = require('./routes/userList'); const databaseList = require('./routes/databaseList'); //解决跨域问题 app.all('*', (req, res, next) => { res.header("Access-Control-Allow-Origin", req.headers.origin); //设置来源 res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS"); res.header("Access-Control-Max-Age", "604800000"); res.header("Access-Control-Allow-Credentials", true); res.header("X-Powered-By", ' 3.2.1'); // res.header("Content-Type", "application/json;charset=utf-8"); next(); }); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); //设置并使用session中间件 app.use(session({ secret: 'Nobody will know this secret shit, else me and the God', cookie: { maxAge: 1000 * 60 * 60 * 24 * 7 }, saveUninitialized: true, name: 'CSA_Uid' })); app.use(express.static(path.join(__dirname, 'public'))); app.use('/v1/captcha', captcha); app.use('/v1/signup', signup); app.use('/v1/signin', signin); app.use('/v1/signout', signout); app.use('/v1/index', index); app.use('/v1/index/userList', userList); app.use('/v1/index/databaseList', databaseList); app.listen(80);