Skip to content

Instantly share code, notes, and snippets.

@CatzillaOrz
Last active October 29, 2017 08:16
Show Gist options
  • Save CatzillaOrz/aaa54a0fbdbd69a454d8f724311e6064 to your computer and use it in GitHub Desktop.
Save CatzillaOrz/aaa54a0fbdbd69a454d8f724311e6064 to your computer and use it in GitHub Desktop.
Node端处理跨域及处理前端路由重定向-Access-Control-Allow-Origin
'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