Unauthorized Access: Azure Web App and Typescript - "Access to this directory or page is restricted."

After developing a NodeJS server in Typescript, I attempted to deploy it to an Azure Web App through VS19. While the project functions correctly internally, when published to Azure, I encountered permission issues.

The project was built using the "Basic Azure Node.js Express 4 Application" template available in VS19.

My understanding is that Azure utilizes IIS to host Typescript applications within an Azure Web App, hence requiring a web.config file, which I have included below.

I made a simple adjustment from "app.js" to "index.js," matching the name of my main app source file.

Upon accessing the Kudu web app shell, I noticed that the output of the Typescript compilation is structured as follows:


        |-wwwroot
        |---dist
        |-----src
        |--------index.js
        |--------index.js.map
        |--------environments
        |--------middlewares
        ...
    

In reality, "index.js" and "index.js.map" should ideally be at the same level as "src."

To address this discrepancy, I adjusted the configuration of the Azure Web App to redirect its root virtual path to: site\wwwroot\dist\src.

If this change was not implemented, the application would return: "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

Currently, although the application attempts to access the resources, it encounters a permission issue displaying: "You do not have permission to view this directory or page."

I am considering altering the web.config file, but I have limited documentation on how to proceed and whether this is the right approach.

Here is an overview of the folder structure:

https://i.sstatic.net/JMqgS.png

tsconfig.json:

{
      "compilerOptions": {
        "module": "commonjs",
        "esModuleInterop": true,
        "target": "es5",
        "outDir": "./dist",
        "baseUrl": ".",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true
      },
      "include": [
        "src/**/*"
      ],
      "exclude": [
        "node_modules"
      ]
    }
    

package.json (excluding dependencies):

{
      "name": "project",
      "version": "1.0.0",
      "description": "Backend",
      "main": "index.js",
      "scripts": {
        "test": "jest --verbose",
        "test-watch": "jest --verbose --watchAll",
        "dev": "nodemon --watch src -e js,ts,json --exec \"ts-node src/index.ts\"",
        "build": "tsc --build",
        "clean": "tsc --build --clean"
      },
      "repository": {
        "type": "git",
        "url": ""
      },
      "author": "",
      "license": "ISC",
      "bugs": {
        "url": ""
      },
      "homepage": "",
      "devDependencies": {
        "@types/cors": "^2.8.13",
        "@types/express": "^4.17.17",
        "@types/jest": "^28.1.8",
        ...
      }
    }
    

web.config


        <?xml version="1.0" encoding="utf-8"?>
        <configuration>
            <appSettings>
            </appSettings>
            <system.webServer>
                <staticContent>
                    <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
                </staticContent>
                <modules runAllManagedModulesForAllRequests="false" />
                <iisnode watchedFiles="web.config;*.js;routes\*.js;views\*.pug"/>
                <handlers>
                    <add name="iisnode" path="index.js" verb="*" modules="iisnode" />
                </handlers>
                <rewrite>
                    <rules>
                        <clear />
                        <rule name="app" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
                            <match url="iisnode.+" negate="true" />
                            <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                            <action type="Rewrite" url="index.js" />
                        </rule>     
                    </rules>
                </rewrite>
            </system.webServer>
        </configuration>
    

Answer №1

  • I successfully set up a Node.js Express app on my local machine using terminal commands and it ran without any issues.

  • Encountering deployment problems in Visual Studio 2019 and Visual Studio 2022, I switched to using Visual Studio Code.

  • Furthermore, I created a web application on Azure for testing purposes.

  • Successfully deployed the Express app to the web app on Azure as well, verification details provided below.

During the web app running process, an error occurred, please refer to the attached image below.

  • Outlined is the file structure path for reference.

  • After including new application settings in the web app configuration, the application runs smoothly.
  • SCM_DO_BUILD_DURING_DEPLOYMENT must be set to True.

Refer to the information below for confirmation:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Move after a specified amount of time

I'm struggling to implement a 6-second redirect in my Angular application that will take users to the homepage. The only resources I've found on this topic are for AngularJS. --------------------UPDATE--------------- Here are my current routes: ...

Buffer.from in Node.js exposes program context leakage

Have you encountered a bug where the Buffer.from() function reads outside of variable bounds when used with strings? I experienced some unusual behavior on my backend, where concatenating 2 buffers resulted in reading contents of variables and beyond, inc ...

Declaring Objects and Relationships in Angular Models

Wondering if it's possible to declare an object inside my model. First attempt: export class Employee{ emp_id: number; emp_fname: string; emp_lname: string; emp_birth: string; emp_status: string; emp_photo: string; emp_dep ...

Error code 0x800a1391 - JavaScript runtime error: 'module' has not been defined

My background is in C++ and I am just beginning to explore TypeScript. I'm facing a runtime error while trying to implement a design (interface/class) that spans multiple files. The error message reads: 0x800a1391 - JavaScript runtime error: 'mod ...

In Typescript, we can use a class to encapsulate another class and then return a generic result

Trying to wrap my head around the concept of generic classes, and now I need to dynamically create another class. However, I am uncertain about how to go about it. Class A {} Class B<T> { Return T } Const c = B(A); // which is T More context on w ...

Utilizing Directives to Embed Attributes

My current challenge involves changing the fill color of attributes in an in-line SVG using Angular and TypeScript. The goal is to have the SVG elements with a "TA" attribute change their fill color based on a user-selected color from a dropdown menu. Howe ...

Issue reported: "Usage of variable 'someVar' before assignment" ; however, it is being properly assigned before usage

This piece of code showcases the issue: let someVar: number; const someFunc = async () => { someVar = 1; } await someFunc(); if (someVar == 1) { console.log('It is 1'); } As a result, you will encounter ...

Do Angular lifecycle hooks get triggered for each individual component within a nested component hierarchy?

I'm exploring the ins and outs of Angular lifecycle hooks with a conceptual question. Consider the following nested component structure: <parent-component> <first-child> <first-grandchild> </first-grandchild& ...

Unlocking Column Data Tooltips in Angular Datatables: A Step-by-Step Guide

I have a single datatable and was wondering how to implement tooltips for when hovering over table cells. I tried the following code snippet, which successfully populated the tooltips. However, I am interested in achieving the same functionality using Angu ...

Error: Unable to locate specified column in Angular Material table

I don't understand why I am encountering this error in my code: ERROR Error: Could not find column with id "continent". I thought I had added the display column part correctly, so I'm unsure why this error is happening. <div class="exa ...

How to utilize the Hide/Unhide data series feature in Chart.js with Angular 2

Currently utilizing PrimeNG charts that utilize chartJS as the foundation. I am exploring a scenario where I want to hide/show a specific data series using an external button. Usually, this is achieved by clicking on the label of the relevant data series ...

Error message: Unable to locate module when utilizing my alternative library packaged with Rollup

Currently, I am utilizing rollup to package a UI library for use across various primary applications. However, the bundled ESM file contains imports that are incompatible with webpack in the main applications: import { ArrowDropDownCircleOutlined } from &a ...

How do I connect TypeORM to multiple databases?

I am faced with the challenge of creating tables in two different databases using TypeORM. Each table is associated with a specific database through the use of the @Entity decorator. However, I encounter an error stating that user x does not have write acc ...

The cucumber step definition will wait until a specific value in mongo has been marked as "COMPLETED"

When initiating a conversion using a starting conversion service, there is a field in my Mongo database that tracks the status of the conversion: ready, runningA, runningB, DONE. How can I create a step definition that will pause execution until the statu ...

The compilation fails when using TestUtils findRenderedComponentWithType with a Component<Props> definition

Content of the file package.json: { "scripts": { "test": "tsc --project . --noEmit" }, "dependencies": { "@types/react": "^16.7.6", "@types/react-dom": "^16.0.9", "react": "^16.6.3", "react-dom": "^16.6.3", "typescript": "^3. ...

What is the best method to condense an array or extract only the valid values?

Looking to find the total count of properties that are true from an array of objects? Here's an example: let data = [ { comment: true, attachment: true, actionPlan: true }, { whenValue: '', ...

Is it possible to apply a formatting filter or pipe dynamically within an *ngFor loop in Angular (versions 2 and 4

Here is the data Object within my component sampleData=[ { "value": "sample value with no formatter", "formatter": null, }, { "value": "1234.5678", "formatter": "number:'3.5-5'", }, { "value": "1.3495", "formatt ...

Convert a generic observable list to a generic list

Can an array containing [Observable<string>, Observable<number>] be converted to [string, number] using generics? function example(obs: Observable<any>[]): any[] { } Intended Outcome: example(of(''), of(0)) // should return [st ...

Transform the subscription into a string

When I use the http method to retrieve a single user, the output logged in the console looks like this: this.usersService.getOneUser().subscribe(data => { console.log(data) }); email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data- ...

Utilizing IonPage and DeepLinkMetadataType in Ionic 3 for tab navigation: Eliminating the need for tab-0

One of the pages on my site contains tabs that are only loaded when clicked: explore.html <ion-tabs> <ion-tab [root]="tab1Root" [tabTitle]="hotTitle" tabIcon="flame"></ion-tab> <ion-tab [root]="tab2Root" [tabTitle]="searchTitle ...