and the package.json also in the api folder where host.json is, right? I did this, it still fails.
I did a very basic function setup now:
package.json:
{
"name": "api",
"version": "1.0.0",
"description": "",
"scripts": {
"start": "func start",
"test": "echo \"No tests yet...\""
},
"dependencies": {
"@azure/functions": "^4.0.0"
},
"devDependencies": {
"azure-functions-core-tools": "^4.0.5455"
}
}
function.json (in api/functionName):
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": ["get"]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
index.js (also in api/functionName):
module.exports = async function (context, req) {
context.res = {
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
},
// status: 200, /* Defaults to 200 */
body: { data: "Hello World from Azure Static Web Apps API!" },
};
};
host.json in api/
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
},
"functionTimeout": "00:10:00"
}
and my github yaml
name: Azure Static Web Apps CI/CD
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened, closed]
branches: [main]
env:
AZURE_FUNCTIONS_ENVIRONMENT: Production
jobs:
build_and_deploy_job:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: ubuntu-latest
name: Build and Deploy Job
steps:
- uses: actions/checkout@v4
with:
submodules: true
lfs: false
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.TOKEN}}
repo_token: ${{ secrets.GITHUB_TOKEN }}
action: "upload"
app_location: "/"
api_location: "api"
output_location: "out"
skip_api_build: false
skip_app_build: false
env:
IS_STATIC_EXPORT: true
AZURE_FUNCTIONS_ENVIRONMENT: Production
NEXT_TELEMETRY_DISABLED: 1
NEXT_BUILD_CACHE: "true"
close_pull_request_job:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Close Pull Request Job
steps:
- name: Close Pull Request
id: closepullrequest
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.TOKEN}}
action: "close"
app_location: "."
The full output is this:
Operation performed by Microsoft Oryx, https://github.com/Microsoft/Oryx
You can report issues at https://github.com/Microsoft/Oryx/issues
Oryx Version: 0.2.20241003.1, Commit: d5352431d933306ccee1be9b5d822c73bf723e9e, ReleaseTagName: 20241003.1
Build Operation ID: dbd5b69d9f28b530
Repository Commit : c4b904b15381f671f8e295815ecc8bafeaf4c75c
OS Type : bullseye
Image Type : githubactions
Detecting platforms...
Detected following platforms:
nodejs: 18.20.8
Version '18.20.8' of platform 'nodejs' is not installed. Generating script to install it...
Source directory : /github/workspace/api
Destination directory: /bin/staticsites/23ac70ca-3d37-4f80-b55c-7df1d7859eff-swa-oryx/api
Downloading and extracting 'nodejs' version '18.20.8' to '/tmp/oryx/platforms/nodejs/18.20.8'...
Detected image debian flavor: bullseye.
Downloaded in 1 sec(s).
Verifying checksum...
Extracting contents...
performing sha512 checksum for: nodejs...
Done in 3 sec(s).
Removing existing manifest file
Creating directory for command manifest file if it does not exist
Creating a manifest file...
Node Build Command Manifest file created.
Using Node version:
v18.20.8
Using Npm version:
10.8.2
Installing production dependencies in '/github/workspace/api/.oryx_prod_node_modules'...
Running 'npm install --production'...
npm warn config production Use `--omit=dev` instead.
added 5 packages, and audited 6 packages in 1s
found 0 vulnerabilities
Copying production dependencies from '/github/workspace/api/.oryx_prod_node_modules' to '/github/workspace/api/node_modules'...
Done in 0 sec(s).
Running 'npm install'...
added 35 packages, and audited 41 packages in 26s
5 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
Copy '/github/workspace/api/node_modules' with all dependencies to '/github/workspace/api/.oryx_all_node_modules'...
Copying production dependencies from '/github/workspace/api/.oryx_prod_node_modules/node_modules' to '/github/workspace/api/node_modules'...
Preparing output...
Copying files to destination directory '/bin/staticsites/23ac70ca-3d37-4f80-b55c-7df1d7859eff-swa-oryx/api'...
Done in 0 sec(s).
Removing existing manifest file
Creating a manifest file...
Manifest file created.
Copying .ostype to manifest output directory.
Done in 36 sec(s).
---End of Oryx build logs---
Function Runtime Information. OS: linux, Functions Runtime: ~4, node version: 18
Finished building function app with Oryx
Zipping Api Artifacts
Done Zipping Api Artifacts
Zipping App Artifacts
Done Zipping App Artifacts
Uploading build artifacts.
Finished Upload. Polling on deployment.
Status: InProgress. Time: 0.2073188(s)
Status: Failed. Time: 15.5981194(s)
Deployment Failed :(
Deployment Failure Reason: Failed to deploy the Azure Functions.
For further information, please visit the Azure Static Web Apps documentation at https://docs.microsoft.com/en-us/azure/static-web-apps/
If you believe this behavior is unexpected, please raise a GitHub issue at https://github.com/azure/static-web-apps/issues/
Exiting