Development vs Production
API Master provides different build modes for development and production environments.- Development
- Production
Run the development server with hot-reloading:This uses
nodemon and ts-node to automatically restart the server when files change.Building the Project
API Master includes two build methods defined inpackage.json.
Standard TypeScript Build
Compile TypeScript files to JavaScript:tsc) and outputs to the dist/ directory:
package.json
esbuild Bundled Build
Create a single bundled file using esbuild:dist/app.cjs file with all dependencies bundled:
package.json
esbuild Options Explained:
--bundle- Bundle all dependencies into one file--platform=node- Target Node.js environment--format=cjs- Output CommonJS format--external:@aws-sdk/client-s3- Exclude AWS SDK from bundle--outfile=dist/app.cjs- Output path
IIS Deployment
API Master includes aweb.config file for deploying to Windows IIS with iisnode.
Prerequisites
Install iisnode
Download and install iisnode for Windows Server or IIS.
web.config Configuration
The project includes a pre-configuredweb.config file:
web.config
Deployment Steps
Copy Files to IIS Directory
Copy these files and folders to your IIS application directory:
dist/directorynode_modules/directoryuploads/directory (create if not exists)package.jsonweb.config
Set Directory Permissions
Grant IIS application pool identity write permissions to:
uploads/directoryApp_Data/directory (for iisnode logs)
Environment-Specific CORS
Configure CORS differently for production to enhance security:app.ts
The current implementation in
app.ts:9-13 uses origin: '*' which should be restricted in production.Production Best Practices
Environment Variables
- Never commit
.envfiles to version control - Use IIS Configuration Editor or system environment variables
- Set
NODE_ENV=production
CORS Configuration
- Replace
origin: '*'with specific domains - Enable
credentials: trueonly if needed - Limit
methodsto required HTTP verbs
File Upload Security
- Implement file type validation in
userRoutes.ts - Set file size limits with multer:
Error Handling
- Disable
devErrorsEnabledinweb.config - Implement proper error logging
- Return generic error messages to clients
Static File Security
- Ensure
uploads/directory has correct permissions - Consider serving uploads through a CDN
- Implement authentication for sensitive files
IIS Deployment Checklist:
- Build project with
npm run build - Copy
dist/,node_modules/,package.json,web.config - Create
uploads/directory with write permissions - Update
web.configentry point todist/app.js - Configure environment variables in IIS
- Restrict CORS origins to production domains
- Test file upload endpoint
- Verify static file serving from
/uploads
Troubleshooting
IIS Deployment Issues
| Issue | Solution |
|---|---|
| 500 Internal Server Error | Enable loggingEnabled="true" in web.config and check App_Data/logs |
| Files not uploading | Verify uploads/ directory exists and has write permissions |
| CORS errors | Update corsOptions.origin in app.ts to include your domain |
| Module not found | Ensure node_modules/ is deployed and npm install was run |
Build Issues
Next Steps
After deploying your API:- Test the API endpoints - Upload files and verify responses
- Configure CORS - Secure your production environment