Skip to content

Commit

Permalink
kuayu
Browse files Browse the repository at this point in the history
  • Loading branch information
Silin7 committed Oct 9, 2020
1 parent 01d850e commit 8414c13
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
28 changes: 14 additions & 14 deletions wsl-project-node/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,19 @@ app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

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

//设置跨域访问
app.all('*', function (req, res, next) {
if (req.method.toLowerCase() == 'options') {
res.send(200); //让options尝试请求快速结束
}
else {
next();
}
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods","*");
res.header("Access-Control-Allow-Headers", "Content-Type");
res.header("Content-Type", "application/json/text/html;charset=UTF-8");
next();
});
// app.all('*', (req, res, next) => {
// console.log('设置跨域访问')
// res.header("Access-Control-Allow-Origin", "*");
// res.header("Access-Control-Allow-Headers", "X-Requested-With");
// res.header("Access-Control-Allow-Methods","*");
// res.header("X-Powered-By",' 3.2.1')
// res.header("Content-Type", "*");
// // res.header("Content-Type", "application/json/html;charset=utf-8");
// next();
// });

// catch 404 and forward to error handler
app.use(function (req, res, next) {
Expand All @@ -45,9 +42,12 @@ app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
});

console.log('服务器启动成功......')

module.exports = app;
15 changes: 12 additions & 3 deletions wsl-project-node/routes/login.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
var express = require('express');
var router = express.Router();
var loginMoudle = require('./compontent/login')
var loginMoudle = require('./compontent/loginMoudle')

router.get('/register', loginMoudle.register);
router.post('/register2', loginMoudle.register2);
// router.get('/get_register', loginMoudle.get_register);
// router.post('/post_register', loginMoudle.post_register);

router.get('/get_register', (req, res, next) => {
console.log('GET')
res.end('HELLO GET')
});
router.post('/post_register', (req, res, next) => {
console.log('POST')
res.end('HELLO POST')
});

module.exports = router;
2 changes: 2 additions & 0 deletions wsl-project-web/src/api/api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import axios from 'axios'
import baseConfig from './baseConfig'
axios.defaults.baseURL = baseConfig.baseURL;
// axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8';
axios.defaults.headers.post['Access-Control-Allow-Origine'] = '*';

import api_login from './components/login'

Expand Down
4 changes: 2 additions & 2 deletions wsl-project-web/vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ module.exports = {
hotOnly: false,
/* 使用代理 */
proxy: {
'/api': {
'/': {
/* 目标代理服务器地址 */
target: 'http://localhost:3000/api',
target: 'http://localhost:3000',
/* 允许跨域 */
changeOrigin: true,
},
Expand Down

0 comments on commit 8414c13

Please sign in to comment.