Select Git revision
-
Lansana DIOMANDE authoredLansana DIOMANDE authored
server.js 4.89 KiB
/**
* This file allow CORS for *.deadlock.io
* from the CORS middleware
* To generate the file you have to run Theia Docker-Java version from https://hub.docker.com/r/theiaide/theia-java
* then you will find the content within /home/theia/src-gen/backend/server.js in the container
*/
// @ts-check
require('reflect-metadata');
// Patch electron version if missing, see https://github.com/eclipse-theia/theia/pull/7361#pullrequestreview-377065146
if (typeof process.versions.electron === 'undefined' && typeof process.env.THEIA_ELECTRON_VERSION === 'string') {
process.versions.electron = process.env.THEIA_ELECTRON_VERSION;
}
const path = require('path');
const express = require('express');
const { Container } = require('inversify');
const { BackendApplication, CliManager } = require('@theia/core/lib/node');
const { backendApplicationModule } = require('@theia/core/lib/node/backend-application-module');
const { messagingBackendModule } = require('@theia/core/lib/node/messaging/messaging-backend-module');
const { loggerBackendModule } = require('@theia/core/lib/node/logger-backend-module');
const container = new Container();
container.load(backendApplicationModule);
container.load(messagingBackendModule);
container.load(loggerBackendModule);
//CORS middleware
const allowCrossDomain = function (req, res, next) {
if (req.headers.origin && req.headers.origin.endsWith('.deadlock.io')) {
res.setHeader('Access-Control-Allow-Origin', req.headers.origin);
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,Content-Type');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE');
}
next();
};
function load(raw) {
return Promise.resolve(raw.default).then((module) => container.load(module));
}
function start(port, host, argv) {
if (argv === undefined) {
argv = process.argv;
}
const cliManager = container.get(CliManager);
return cliManager.initializeCli(argv).then(function () {
const application = container.get(BackendApplication);
application.use(allowCrossDomain);
application.use(express.static(path.join(__dirname, '../../lib')));
application.use(express.static(path.join(__dirname, '../../lib/index.html')));
return application.start(port, host);
});
}
module.exports = (port, host, argv) =>
Promise.resolve()
.then(function () {
return Promise.resolve(require('@theia/core/lib/node/i18n/i18n-backend-module')).then(load);
})
.then(function () {
return Promise.resolve(require('@theia/core/lib/node/hosting/backend-hosting-module')).then(load);
})
.then(function () {
return Promise.resolve(require('@theia/filesystem/lib/node/filesystem-backend-module')).then(load);
})
.then(function () {
return Promise.resolve(require('@theia/filesystem/lib/node/download/file-download-backend-module')).then(load);