我有一个带有 ReactJs 前端的 .NET Core 3.1(我正在使用 switch 仿生框架),我试图在 IIS 上的子文件夹(子应用程序)中运行它。在 IIS 上将应用程序作为网站安装可以正常工作。该应用程序运行没有问题。但是,当在 IIS 默认页面下将应用程序安装为子应用程序时,总是会在任何需要响应的资源上给出 404。这是因为 React 使用的 baseUrl 默认为根 url。
到目前为止,除了将子文件夹名称添加到 baseurl 本身之外,我还没有找到改变这种行为的方法。这对我来说不是一个解决方案,因为这个应用程序将安装在一台服务器上 IIS 下的至少 43 个子文件夹中。我不能仅仅因为必须更新子文件夹就构建和部署超过 43 个应用程序!
有没有人知道如何让反应前端识别正在使用的当前 url(包括子文件夹),而不仅仅是默认为根 url?
我试过设置“主页”:“。” 和 package.json 中的“主页”:“./”,根据来自“gaearon”(https://github.com/facebook/create-react-app/issues/527)的帖子,但它没有影响。
我的配置文件(default.tsx)看起来像这样(2021/04/09 编辑):
import Project from '../src/globals/interfaces/Project';
const isDevelopment = Object.is(process.env.NODE_ENV, 'development');
const baseUrl = isDevelopment ? 'http://localhost:5105' : '.';
const config: IConfigData<Project, {}> = {
core: {
i18n: {
defaultLocale: 'en',
},
},
project: {
baseUrl,
},
runtime: {},
};
export default config;
我的 package.json:
{
"name": "MyApp",
"version": "3.4.2",
"description": "My Application",
"license": "Whatever",
"author": {
"name": "Werner"
},
"config": {
"AppIcon": "./src/assets/appIcon/logo.png",
"title": "My App Title",
"devServer": {
"host": "0.0.0.0",
"port": "5170",
"https": false,
"publicPath": "/"
},
"publicPath": "",
"homepage": ".",
"functionalTestBrowsers": [
"chrome",
"firefox",
"internet explorer",
"edge"
]
},
"scripts": {
"test": "jest --no-cache",
"test:update": "jest --updateSnapshot",
"start": "webpack-dev-server --env.build=dev",
"start:4110": "webpack-dev-server --env.build=dev --env.config=4110",
"start:4120": "webpack-dev-server --env.build=dev --env.config=4120",
"start:4130": "webpack-dev-server --env.build=dev --env.config=4130",
"start:4140": "webpack-dev-server --env.build=dev --env.config=4140",
"start:4150": "webpack-dev-server --env.build=dev --env.config=4150",
"start:legacy": "webpack-dev-server --env.build=dev --env.legacy=true --env.REDUX_TOOLS=logger",
"start:swidget": "webpack-dev-server --port 7070 --env.build=dev --env.swidget=true --env.legacy=true --env.REDUX_TOOLS=logger",
"start:host": "webpack-dev-server --env.build=dev --env.legacy=true --env.exposed=true --env.REDUX_TOOLS=logger",
"build": "webpack --env.build=prod --env.verbose=false",
"build:ci": "webpack --env.build=prod --env.verbose=true --env.release=true",
"build:legacy": "webpack --env.build=prod --env.legacy=true",
"build:host": "webpack --env.build=prod --env.legacy=true --env.exposed=true",
"build:swidget": "webpack --env.build=prod --env.swidget=true --env.legacy=true",
"build:multi": "webpack --env.build=multi",
"build:test:functional": "tsc -p test/functional/tsconfig.json",
"lint": "nyr lint:eslint && nyr lint:stylelint && nyr lint:prettier",
"lint:staged": "lint-staged",
"lint:eslint": "eslint --ext ts,tsx src",
"lint:prettier": "prettier --check \"./**/*\"",
"lint:stylelint": "stylelint \"src/**/*.(css|scss)\" --syntax scss",
"lint:fix": "nyr lint:fix:eslint && nyr lint:fix:stylelint && nyr lint:fix:postcss && nyr lint:fix:prettier",
"lint:fix:prettier": "prettier --write \"./**/*\"",
"lint:fix:postcss": "postcss --config postcss.config.js --env sort-only --no-map --replace \"src/**/*.(css|scss)\"",
"lint:fix:stylelint": "stylelint \"src/**/*.(css|scss)\" --syntax scss --fix",
"lint:fix:eslint": "eslint --fix --ext ts,tsx src",
"clean": "rimraf dist && rimraf coverage",
"storybook": "cross-env build=dev start-storybook -p 9001 -c .build/storybook",
"storybook:static": "cross-env build=prod build-storybook -c .build/storybook -o dist/storybook",
"test:functional": "run-p build:test:functional test:functional:selenium && run-p --race start wdio",
"test:functional:headless": "run-p build:test:functional test:functional:selenium && run-p --race start wdio:headless",
"test:functional:selenium": "selenium-standalone install --silent",
"wdio": "wdio .build/wdio.conf.js",
"wdio:headless": "cross-env WDIO_HEADLESS=true wdio .build/wdio.conf.js"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"post-commit": "git update-index --again"
}
},
"repository": {
"type": "git",
"url": "Don't worry! Taken out for security!"
},
"engines": {
"node": ">=8.11.3",
"npm": ">=5.6.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"Firefox ESR",
"ie >= 11"
],
"dependencies": {
"@daimler/material-ui-comps": "0.0.4-release-84.0",
"@daimler/material-ui-theme": "0.0.9",
"@daimler/typeface-daimler-cs-web": "^1.0.0",
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.53",
"@switch/core": "2.0.0-beta.2",
"@types/react-csv": "^1.1.1",
"@types/react-router-dom": "^5.1.3",
"@types/redux-logger": "^3.0.7",
"axios": "^0.19.0",
"core-js": "~3.2.1",
"domtokenlist-shim": "~1.2.0",
"file-saver": "^2.0.2",
"inversify": "~4.3.0",
"joi-browser": "~13.4.0",
"jwt-decode": "^2.2.0",
"material-table": "^1.69.1",
"material-ui-dropzone": "^3.2.1",
"react": "~16.9.0",
"react-csv": "^2.0.3",
"react-dom": "~16.9.0",
"react-hot-loader": "~4.12.11",
"react-promise-tracker": "^2.0.5",
"react-redux": "^7.2.0",
"react-router-dom": "^5.1.2",
"react-switch": "^5.0.1",
"react-table": "^7.5.1",
"react-transition-group-v2": "^4.3.0",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0",
"regenerator-runtime": "~0.13.3",
"tslib": "~1.10.0",
"typesafe-actions": "^5.1.0",
"universal-cookie": "^4.0.3",
"whatwg-fetch": "~3.0.0"
},
"devDependencies": {
"@babel/core": "~7.5.5",
"@babel/preset-env": "~7.5.5",
"@babel/runtime": "~7.5.5",
"@hot-loader/react-dom": "~16.9.0",
"@storybook/addon-actions": "~5.1.11",
"@storybook/addon-info": "~5.1.11",
"@storybook/addon-knobs": "~5.1.11",
"@storybook/addon-links": "~5.1.11",
"@storybook/addons": "~5.1.11",
"@storybook/cli": "~5.1.11",
"@storybook/react": "~5.1.11",
"@types/enzyme": "~3.10.3",
"@types/jasmine": "~3.4.0",
"@types/jest": "~24.0.18",
"@types/jwt-decode": "^2.2.1",
"@types/node": "~12.0.0",
"@types/prop-types": "~15.7.1",
"@types/react": "~16.9.2",
"@types/react-dom": "~16.9.0",
"@types/react-redux": "^7.1.7",
"@types/react-test-renderer": "~16.9.0",
"@types/storybook__addon-actions": "~3.4.3",
"@types/storybook__addon-info": "~4.1.2",
"@types/storybook__addon-knobs": "~5.0.3",
"@types/storybook__addon-links": "~3.3.5",
"@types/storybook__react": "~4.0.2",
"@typescript-eslint/eslint-plugin": "~2.0.0",
"@typescript-eslint/parser": "~2.0.0",
"@wdio/cli": "~5.12.4",
"@wdio/dot-reporter": "~5.12.1",
"@wdio/jasmine-framework": "~5.12.1",
"@wdio/local-runner": "~5.12.4",
"@wdio/selenium-standalone-service": "~5.12.1",
"@wdio/spec-reporter": "~5.12.1",
"@wdio/sync": "~5.12.3",
"babel-loader": "~8.0.6",
"clean-webpack-plugin": "~3.0.0",
"copy-webpack-plugin": "~5.0.4",
"cross-env": "~5.2.0",
"css-loader": "~3.2.0",
"css-modules-typescript-loader": "~3.0.0",
"cssjson": "~2.1.3",
"duplicate-package-checker-webpack-plugin": "~3.0.0",
"enzyme": "~3.10.0",
"enzyme-adapter-react-16": "~1.14.0",
"enzyme-to-json": "~3.4.0",
"eslint": "~6.2.1",
"eslint-config-prettier": "~6.1.0",
"eslint-plugin-prettier": "~3.1.0",
"eslint-plugin-react": "~7.14.3",
"expose-loader": "~0.7.5",
"fork-ts-checker-webpack-plugin": "~1.5.0",
"html-webpack-multi-build-plugin": "~1.0.0",
"html-webpack-plugin": "~3.2.0",
"husky": "~3.0.4",
"identity-obj-proxy": "~3.0.0",
"imagemin-lint-staged": "~0.4.0",
"jasmine": "~3.4.0",
"jest": "~24.9.0",
"lint-staged": "~9.2.3",
"mini-css-extract-plugin": "~0.8.0",
"mock-local-storage": "~1.1.8",
"npm-run-all": "~4.1.5",
"nyr": "1.1.0",
"optimize-css-assets-webpack-plugin": "~5.0.3",
"postcss": "~7.0.17",
"postcss-cli": "~6.1.3",
"postcss-extend": "~1.0.5",
"postcss-import": "~12.0.1",
"postcss-import-sync": "~7.1.4",
"postcss-loader": "~3.0.0",
"postcss-nested": "~4.1.2",
"postcss-preset-env": "~6.7.0",
"postcss-remove-prefixes": "~1.2.0",
"postcss-sorting": "~5.0.1",
"postcss-unprefix": "~2.1.4",
"prettier": "~1.18.2",
"react-ace": "^7.0.4",
"react-docgen-typescript-loader": "~3.1.1",
"react-test-renderer": "~16.9.0",
"rimraf": "~3.0.0",
"simple-progress-webpack-plugin": "~1.1.2",
"style-loader": "~1.0.0",
"stylelint": "~10.1.0",
"stylelint-config-css-modules": "~1.4.0",
"stylelint-config-recommended": "~2.2.0",
"terser-webpack-plugin": "~1.4.1",
"ts-jest": "~24.0.2",
"ts-loader": "~6.0.4",
"typescript": "~3.5.3",
"url-loader": "~2.1.0",
"webapp-webpack-plugin": "~2.7.1",
"webpack": "~4.39.2",
"webpack-cli": "~3.3.7",
"webpack-dev-server": "~3.8.0",
"webpack-merge": "~4.2.1"
}
}
任何帮助将不胜感激。