Azure node.js与graphql cli的相对路径

时间:2018-04-09 18:40:52

标签: node.js azure prisma

我有一个小的node.js应用程序,它充当使用graphql-cli创建的graph-api。 在localhost上一切正常,但是当我尝试在azure中运行它作为Web应用程序时,我似乎遇到路径问题。以下代码段正在运行运行npm start

的localhost
const server = new GraphQLServer({
  typeDefs: './src/schema.graphql',
  resolvers,
  context: req => ({
    ...req,
    db: new Prisma({
      typeDefs: 'src/generated/prisma.graphql',
      endpoint: 'xxx',
      secret: 'xxx',
      debug: true,
    }),
  }),
})

定义了一个.graphql文件的路径:

typeDefs: './src/schema.graphql',

考虑到index.js与schema.graphql位于同一文件夹中的文件夹结构,我觉得有点奇怪

enter image description here

无论如何,这是在localhost上工作,但是当尝试将其作为azure web应用程序运行时,我收到以下错误:

No schema found for path: D:\home\site\wwwroot\src\src\schema.graphql

由于这只是一个脚手架应用程序,我不想更改代码中的路径。我不认为他们错了,因为它正在使用localhost。我想我在azure上缺少一些配置。

这是我的web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <webSocket enabled="false" />
    <handlers>      
      <add name="iisnode" path="src/index.js" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>        
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^src/index.js\/debug[\/]?" />
        </rule>
        <rule name="StaticContent">
          <action type="Rewrite" url="public{REQUEST_URI}"/>
        </rule>        
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="src/index.js"/>
        </rule>
      </rules>
    </rewrite>    
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin"/>
        </hiddenSegments>
      </requestFiltering>
    </security>
    <httpErrors existingResponse="PassThrough" />
  </system.webServer>
</configuration>

我的iisnode.yml看起来就像这样:

nodeProcessCommandLine: "D:\Program Files (x86)\nodejs\8.4.0\node.exe"

我尝试了很多不同的节点版本,但我目前在我的localhost上运行8.4.0,其工作

任何人都有任何想法?

1 个答案:

答案 0 :(得分:0)

您需要将index.js文件移至根目录并将web.config更改为:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <webSocket enabled="false" />
    <handlers>      
      <add name="iisnode" path="index.js" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>        
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^index.js\/debug[\/]?" />
        </rule>
        <rule name="StaticContent">
          <action type="Rewrite" url="public{REQUEST_URI}"/>
        </rule>        
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="index.js"/>
        </rule>
      </rules>
    </rewrite>    
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin"/>
        </hiddenSegments>
      </requestFiltering>
    </security>
    <httpErrors existingResponse="PassThrough" />
  </system.webServer>
</configuration>