Welcome to reprint, reprint with the article source link ~~, I hope my experience can help you, have a problem you can click my avatar plus my wechat this article only to provide a solution to the problems encountered, for those who urgently want to achieve functional effect, I hope to be able to slightly sink down to watch, or directly watch the train of thought, The code of this article can not be used directly, the complete code is only the problem solved in this article to use the code, if directly used may have an error, as long as you modify the code can be used
CesiumLabApkServe does not load when used, browser prompts cross domain
– reference –
Google Chrome cross-domain setup nodeJS, Express allows cross-domain access
Description –
Across domains, there are two main ways:
1, Google Chrome allows cross domain, reference the first reference connection. 2. CesiumLabApkServe Settings allow cross-domain
Thinking –
1. Open the CesiumLabApkServe code and view the app.js file in the root directory. 2, check the package to see the use of express framework, then directly refer to express to solve the cross-domain method.
– process –
Var app = express(); Can be
/ / set the cross-domain Access app. All (' * '(the req, res, next) = > {res. The header (" Access - Control - Allow - Origin ", "*"); res.header("Access-Control-Allow-Headers", "X-Requested-With"); res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS"); Res. The header (" X - Powered By ", '3.2.1) res. The header (" the content-type ", "application/json. charset=utf-8"); next(); });Copy the code
– Complete code –
var createError = require('http-errors'); var express = require('express'); var path = require('path'); var cookieParser = require('cookie-parser'); var logger = require('morgan'); var indexRouter = require('./routes/index'); // var usersRouter = require('./routes/users'); var app = express(); / / set the cross-domain Access app. All (' * '(the req, res, next) = > {res. The header (" Access - Control - Allow - Origin ", "*"); res.header("Access-Control-Allow-Headers", "X-Requested-With"); res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS"); Res. The header (" X - Powered By ", '3.2.1) res. The header (" the content-type ", "application/json. charset=utf-8"); next(); }); // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'pug'); 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(express.static(path.join(__dirname, 'tile'))); app.use('/', indexRouter); // app.use('/users', usersRouter); // catch 404 and forward to error handler app.use(function(req, res, next) { next(createError(404)); }); // error handler 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'); }); module.exports = app;Copy the code