使用sencha app watch正常,sencha app build+Apache部署后功能异常
Hey there! No worries about any language gaps—let’s break down why that specific feature is failing after your production build and deployment to Apache. Here are the most common causes and fixes to try:
1. Check for Path Mismatches
When using sencha app watch, the development server handles resource paths differently than Apache does. A common issue is incorrect relative paths for API calls or static assets (like images, config files).
- Open your browser’s DevTools (F12) and go to the Network tab. Trigger the broken feature and look for any requests with a 404 status code. These will point to resources that Apache can’t find.
- Verify if your API calls are using absolute paths (e.g.,
/api/endpoint) instead of relative ones that might resolve differently in the production setup. If you’re using relative paths, adjust them to match Apache’s document root structure. - Double-check that your Ext JS
app.jsonhas correctresourcesandpathsconfigurations—sometimes the build tool rewrites paths incorrectly for production.
2. Rule Out Minification/Obfuscation Issues
Production builds run code minification and obfuscation, which can break features if variables/functions are renamed unexpectedly.
- First, test with a non-minified build to confirm: run
sencha app build testing(this skips minification) and deploy that build to Apache. If the feature works here, the problem is with minification. - To fix this, edit your
app.jsonand add preserve rules for the affected code. For example, if you have a global functionmyCriticalFunction, add it to thepreservearray under thejsoutput configuration:"output": { "js": { "preserve": [ "myCriticalFunction", "MyApp.util.CustomHelper" ] } } - Avoid using
eval()or dynamic function calls (likewindow[functionName]) in production—these are prone to breakage during obfuscation.
3. Fix File Permissions
Apache runs under a specific user (usually www-data), and soft links to your user’s ~/Projects directory might have restrictive permissions that block access.
- Instead of using a soft link, try copying the build output directly to Apache’s document root:
cp -r ~/Projects/myapp/build/production/myapp /var/www/ - If you prefer using the soft link, adjust permissions on your project directory to allow Apache to read it:
chmod -R 755 ~/Projects/myapp/build/production/myapp chmod 755 ~/Projects ~/Projects/myapp ~/Projects/myapp/build ~/Projects/myapp/build/production
4. Clear Caching Issues
Old cached files in the browser or Apache can cause the app to load outdated code.
- Force a full browser refresh (Ctrl+Shift+R on Windows/Linux, Cmd+Shift+R on Mac) to bypass local cache.
- Check if Apache has caching enabled. If you have an
.htaccessfile, temporarily disable cache rules to test:# Add these lines to .htaccess to disable caching Header set Cache-Control "no-cache, no-store, must-revalidate" Header set Pragma "no-cache" Header set Expires 0
5. Verify CORS Configuration
The development server from sencha app watch often allows cross-origin requests by default, but Apache might not have CORS enabled, causing API calls to fail.
- Check the browser’s Console tab for CORS-related error messages (e.g., "No 'Access-Control-Allow-Origin' header is present").
- If CORS is the issue, add these rules to your Apache
.htaccessfile:
Note: Restrict theHeader set Access-Control-Allow-Origin "*" Header set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" Header set Access-Control-Allow-Headers "Content-Type, Authorization"Allow-Originvalue to your API domain in production instead of using"*"for security.
Start with the simplest checks (path mismatches, caching, permissions) first—these are the most frequent culprits. Let me know if you need help narrowing it down further!
内容的提问来源于stack exchange,提问作者morony

