Last active
October 29, 2017 08:16
-
-
Save CatzillaOrz/aaa54a0fbdbd69a454d8f724311e6064 to your computer and use it in GitHub Desktop.
Node端处理跨域及处理前端路由重定向-Access-Control-Allow-Origin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
import errors from './components/errors'; | |
import path from 'path'; | |
export default function(app) { | |
// Insert routes below | |
app.use(function(req, res, next) { | |
res.header("Access-Control-Allow-Origin", "*"); | |
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); | |
next(); | |
}); | |
app.use('/api/account', require('./api/account')); | |
app.use('/api/user', require('./api/user')); | |
// All undefined asset or api routes should return a 404 | |
app.route('/:url(api|auth|components|app|bower_components|assets)/*') | |
.get(errors[404]); | |
// All other routes should redirect to the index.html | |
app.route('/*') | |
.get((req, res) => { | |
res.sendFile(path.resolve(app.get('appPath') + '/index.html')); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment