Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receiving 401 when inside a container #37

Open
chanm003 opened this issue Aug 23, 2023 · 0 comments
Open

Receiving 401 when inside a container #37

chanm003 opened this issue Aug 23, 2023 · 0 comments

Comments

@chanm003
Copy link

chanm003 commented Aug 23, 2023

On the left terminal, I am running an Express Server that successfully queries an on-premises server using PnP JS.

On the right terminal, I containerize this Express server, and receive a HTTP 401 Unauthorized. Same JS file used in both instances. Can anybody please help?
401-when-express-server-is-containerized

index.js

const express = require('express');
const pnp = require('@pnp/sp');
const { PnpNode } = require('sp-pnp-node');

const app = express();

pnp.sp.setup({
  sp: {
      fetchClientFactory: () => {
          return new PnpNode({
              siteUrl: 'http://40.111.32.91',
              authOptions: {
                  username: 'SP2016-FARM-ADMIN',
                  domain: 'CONTOSO',
                  password: '6tfc0okm<LP_'
              }
          })
      },
      baseUrl: 'http://40.111.32.91'
  }
});

app.get('/', async (req, res) => {
  const lists = await pnp.sp.web.lists.get();
  console.log(`Number of lists: ${lists.length}`)
  res.json({ username: `${lists.length}` });
});

app.listen(8880, () => console.log('Server on port 8880.'));

docker-compose.yml

version: '3'
services:
  nodejs_api:
    image: docker-pnpjs
    container_name: docker-pnpjs
    build:
      context: .
      dockerfile: Dockerfile
    env_file: ./docker-compose-backend.env
    ports:
      - "8880:8880"
    command: npm run dev
    volumes:
      - /app/node_modules
      - .:/app

Dockerfile

FROM node:16

RUN ["apt-get", "update"]
RUN ["apt-get", "install", "-y", "vim"]

WORKDIR /app

COPY package*.json ./

RUN npm install
RUN npm install -g nodemon

COPY . .

EXPOSE 8880

package.json

{
    "name": "docker-pnpjs",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
        "start": "node index.js",
        "dev": "nodemon --legacy-watch index.js",
        "test": "echo \"Error: no test specified\" && exit 1"
    },
    "dependencies": {
        "@pnp/pnpjs": "^1.3.11",
        "express": "^4.17.1",
        "sp-pnp-node": "^3.0.1"
    },
    "devDependencies": {
        "nodemon": "^2.0.12"
    },
    "author": "Mike Chan",
    "license": "ISC"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant