I’m running into an issue where if I have a form on a page with method="POST"
then I’m getting a 405 Method Not Allowed response. I’ve tried issuing a POST request even with Insomnia but I don’t see that request in the Azure CLI logs when I run with swa start
. What could be the issue here?
+page.svelte
<script lang="ts">
import { Button, Heading, Label, P, Input, Select, Hr, A } from 'flowbite-svelte';
</script>
<div>
<form method="POST">
<Input
data-testid="onboarding-workspace-name-input"
id="workspace-name-input"
name="workspace-name"
class="text-sm mt-2"
required
maxlength="16"
bind:value={workspaceName}
/>
<Button data-testid="onboarding-submit-button" class="w-full mt-6 text-sm" type="submit"
>Submit</Button
>
</form>
</div>
+page.server.ts
import type { Actions } from '@sveltejs/kit';
export const actions: Actions = {
default: async ({locals, request}) => {
console.log('hello from onboarding page.server.ts');
}
};
staticwebapp.config.json
{
"responseOverrides": {
"401": {
"redirect": "/.auth/login/aad?post_login_redirect_uri=.referrer",
"statusCode": 302
}
},
"routes": [
{
"route": "/onboarding",
"allowedRoles": ["anonymous", "authenticated"],
"methods": ["GET", "POST"]
}
]
}
How I start on local:
swa build && swa start --data-api-location swa-db-connections
swa-cli.config.json
{
"$schema": "https://aka.ms/azure/static-web-apps-cli/schema",
"configurations": {
"basel": {
"outputLocation": "./build/static",
"appBuildCommand": "npm run build",
"run": "vite dev",
"appDevserverUrl": "http://localhost:5173"
}
}
}
I really though adding methods: ["GET", "POST"]
on the onboarding route would do it, but when I run the server and issue a POST request to http://localhost:4280/onboarding
, I don’t even see the request get logged in the terminal.