Plesk Windows deploy node.js

て烟熏妆下的殇ゞ 提交于 2019-12-24 01:39:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!