【问题标题】:Azure node.js relative paths with graphql cli带有 graphql cli 的 Azure node.js 相对路径
【发布时间】:2018-09-19 05:50:40
【问题描述】:

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

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 位于同一文件夹中的文件夹结构,我觉得有点奇怪

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

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

由于这只是一个脚手架应用程序,我不想更改代码中的路径。我不认为他们错了,因为它在本地主机上工作。我在想我在 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"

我尝试了很多不同的节点版本,但我目前在我的本地主机上运行 8.4.0

有人有什么想法吗?

【问题讨论】:

    标签: node.js azure prisma


    【解决方案1】:

    您需要将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>
    

    【讨论】:

    • 是的,这将使它在 azure 上工作,但它仍然不能解释为什么它在 localhost 上工作。我真的觉得我的天蓝色设置缺少一些东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-18
    • 1970-01-01
    • 1970-01-01
    • 2019-07-18
    • 2020-12-07
    • 2017-05-18
    相关资源
    最近更新 更多