问题
I have created an Angular project with Node.js as a backend.
This is the server file structure:
Home directory
- httpdocs
- node-hm
- dist
- browser(folder)
- server (folder)
- server.js
- package.json
- web.config
I have managed to "npm install" from the Node.js menu in plesk.
Tried to:
- change the Application Startup File to "dist/server.js".
- change document root to "node-hm/dist" folder.
- copy dist file to "node-hm" - only the index is loaded, other files like CSS won't load
What am I missing?
回答1:
found the answer here:
https://talk.plesk.com/threads/use-nodejs-and-problem-with-express-routing.343510/
need to modify web.config to serve the static files
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="myapp">
<match url="/*" />
<action type="Rewrite" url="server.js" />
</rule>
<!-- Don't interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?" />
</rule>
</rules>
</rewrite>
and define in server.js:
app.use(express.static('dist/browser'));
来源:https://stackoverflow.com/questions/51654776/plesk-windows-deploy-node-js