Plesk Windows deploy node.js

2019-08-05 08:28发布

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. enter image description here

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条回答
等我变得足够好
2楼-- · 2019-08-05 09:06

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'));
查看更多
登录 后发表回答