Merge pull request #823 from directus/subpaths

Allow App to run under subpath
This commit is contained in:
Rijk van Zanten
2020-10-30 23:37:25 +01:00
committed by GitHub
6 changed files with 27 additions and 8 deletions

5
api/index.js Normal file
View File

@@ -0,0 +1,5 @@
module.exports = {
createApp: require('./dist/app').default,
...require('./dist/exceptions'),
...require('./dist/services'),
};

View File

@@ -46,7 +46,7 @@
"url": "https://github.com/benhaynes"
}
],
"main": "dist/app.js",
"main": "index.js",
"bin": {
"directus": "cli.js"
},

View File

@@ -44,6 +44,8 @@ import { InvalidPayloadException } from './exceptions';
import { registerExtensions } from './extensions';
import emitter from './emitter';
import fse from 'fs-extra';
export default async function createApp() {
validateEnv(['KEY', 'SECRET']);
@@ -81,10 +83,16 @@ export default async function createApp() {
if (env.NODE_ENV !== 'development') {
const adminPath = require.resolve('@directus/app/dist/index.html');
app.get('/', (req, res) => res.redirect('/admin/'));
// Prefix all href/src in the index html with the APIs public path
let html = fse.readFileSync(adminPath, 'utf-8');
html = html.replace(/href="\//g, `href="${env.PUBLIC_URL}`);
html = html.replace(/src="\//g, `src="${env.PUBLIC_URL}`);
app.get('/', (req, res) => res.redirect(`${env.PUBLIC_URL}/admin/`));
app.get('/admin', (req, res) => res.send(html));
app.use('/admin', express.static(path.join(adminPath, '..')));
app.use('/admin/*', (req, res) => {
res.sendFile(adminPath);
res.send(html);
});
}

View File

@@ -57,7 +57,9 @@ async function getEnvInfo(event: string) {
transport: env.EMAIL_TRANSPORT,
},
oauth: {
providers: env.OAUTH_PROVIDERS,
providers: env.OAUTH_PROVIDERS.split(',')
.map((v: string) => v.trim())
.filter((v: string) => v),
},
db_client: env.DB_CLIENT,
};
@@ -65,7 +67,9 @@ async function getEnvInfo(event: string) {
function getStorageDrivers() {
const drivers: string[] = [];
const locations = env.STORAGE_LOCATIONS;
const locations = env.STORAGE_LOCATIONS.split(',')
.map((v: string) => v.trim())
.filter((v: string) => v);
for (const location of locations) {
const driver = env[`STORAGE_${location.toUpperCase()}_DRIVER`];

View File

@@ -4,8 +4,8 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
<link rel="shortcut icon" href="/favicon.ico">
<link rel="manifest" href="/manifest.webmanifest" />
<link rel="shortcut icon" href="/admin/favicon.ico">
<link rel="manifest" href="/admin/manifest.webmanifest" />
<title>Loading...</title>
<style id="custom-css"></style>
</head>

View File

@@ -1,4 +1,6 @@
__webpack_public_path__ = (window as any).$directusAssetBasePath || '/admin/';
import getRootPath from './utils/get-root-path';
__webpack_public_path__ = getRootPath() + 'admin/';
import { version } from '../package.json';