Tiny REST API server implemented using ExpressJS and Prisma Client that connects to a SQL Server database.
The purpose of this example is to try Azure App Service Hybrid Connections. Thus the ExpressJS server and the SQL server should be deployed on Azure App Service and on-prem, respectively.
You must have a SQL server up and running.
-
Download the repo and install all dependencies:
git clone https://github.com/francescobarbarulo/expressjs-sqlserver-app.git cd expressjs-sqlserver-app npm install
-
Create the
.env
file with the following database connection string:DATABASE_URL="sqlserver://<hostname>:1433;database=<db>;user=sa;password=<passwd>;trustServerCertificate=true"
-
Create and seed the database:
npx prisma migrate dev --name init
-
Test locally the REST API server:
npm run start
The server starts by default on port
3000
, but you can chenge it by adding aPORT
attribute in the.env
file:PORT=8080
-
Deploy the app on Azure App Service. A Node.js web app con be easily deployed on the App Service by following the offical Microsoft documentation.
-
From the Azure portal, set the
DATABASE_URL
parameter (the same of the.env
file) in application settings tab under the "Configuration" tab of the App Service.NOTE: I was able to deploy successfully only on linux App Service.
-
Create and add an Hybrid Connection the app by following again the official Microsoft documentation.
NOTE: If the status of the connection in the HCM stays "Not Connected" even after following all steps correctly, try to restart the Azure Hybrid Connection Manger Service from the Windows Services Manager.