Express JS:TypeError [ERR_INVALID_ARG_TYPE]:“ url”参数必须为字符串类型。收到的型号

时间:2019-06-28 17:42:59

标签: node.js express next.js koa shopify-app

我正在通过此TUT在shopify build-a-shopify-app-with-node-and-react

中制作一个私人应用

TUT使用koa,但我正在使用express。部分原因是因为我了解表达并希望了解我是否可以抽象化正在发生的事情并将其应用于其他上下文。

当我到达Authenticate and test your app时,他们希望一个人这样做:

  

添加ngrok转发URL和商店的HTTPS版本   指向以下占位符的URL并将其加载到浏览器中:

     

提示   

这会导致我的错误:

TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received type number
    at Url.parse (url.js:154:11)
    at urlParse (url.js:148:13)
    at Object.urlResolve [as resolve] (url.js:659:10)
    at /Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express-shopify-auth/index.js:190:19
    at Function.shop (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/server/server.js:28:14)
    at middleware (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express-shopify-auth/index.js:168:25)
    at Layer.handle [as handle_request] (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:317:13)
    at /Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:335:12)
    at next (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:275:10)
    at session (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express-session/index.js:468:7)
    at Layer.handle [as handle_request] (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:317:13)
    at /Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/Users/antoniopavicevac-ortiz/Sites/scheduled-promo-bar/node_modules/express/lib/router/index.js:335:12)

这是我的server.js:

/* eslint-disable vars-on-top */
require('isomorphic-fetch');
var express = require('express');
var next = require('next');
var ShopifyAuth = require('express-shopify-auth');
var dotenv = require('dotenv');
var session = require('express-session');

dotenv.config();

const port = parseInt(process.env.PORT, 10) || 3000;
var dev = process.env.NODE_ENV !== 'production';
var app = next({ dev });

var { SHOPIFY_API_SECRET_KEY, SHOPIFY_API_KEY } = process.env;

app.prepare().then(() => {
  var auth = ShopifyAuth.create({
    appKey: SHOPIFY_API_KEY,
    appSecret: SHOPIFY_API_SECRET_KEY,
    baseUrl: port,
    authPath: '/auth',
    authCallbackPath: '/auth/callback',
    authSuccessUrl: '/success',
    authFailUrl: '/fail',
    scope: ['read_products'],
    shop(req, done) {
      return done(null, req.query.shop);
    },
    onAuth(req, res, shop, accessToken, done) {
      // save auth info to session
      req.session.shopify = { shop, accessToken };
      return done();
    },
  });

  var server = express();

  server.use(
    session({
      secret: SHOPIFY_API_SECRET_KEY,
      resave: false,
      saveUninitialized: true,
    })
  );

  server.use(auth);

  server.get('/success', function(req, res) {
    res.json(req.session.shopify);
  });

  server.get('/fail', function(req, res) {
    res.send('Authentication failed');
  });

  server.listen(port, () => {
    console.log(`> Ready on http://localhost:${port}`);
  });
});

有人有见识吗?

1 个答案:

答案 0 :(得分:1)

您正在baseurl属性中传递端口,该属性是一个数字。您应该在此处添加网址。