20 lines
1.4 KiB
Markdown
20 lines
1.4 KiB
Markdown
I want to add backend functionality to send the survey responses as an email upon submission using Option 1 (a minimalist Go/Golang microservice).
|
|
|
|
Please complete the following tasks:
|
|
|
|
1. Go Microservice (`main.go`):
|
|
- Create a lightweight HTTP server using standard Go library packages (`net/http`, `net/smtp`, `encoding/json`).
|
|
- Create an endpoint (e.g., `POST /api/submit`) to accept JSON payload survey data from the front end.
|
|
- Configure SMTP credentials and server settings via environment variables (e.g., `SMTP_HOST`, `SMTP_PORT`, `SMTP_USER`, `SMTP_PASS`, `TO_EMAIL`) via an .env file
|
|
- Format the incoming JSON survey data into a clean, readable text body and dispatch the email upon request.
|
|
- Handle CORS preflight (`OPTIONS`) and headers so the HTML/JS front end can POST to it smoothly.
|
|
|
|
2. Dockerization (`Dockerfile`):
|
|
- Provide a multi-stage `Dockerfile` (e.g., compile with `golang:alpine`, copy to `scratch` or `alpine`) to ensure the resulting container image is ultra-lightweight (<20MB).
|
|
|
|
3. Front-End Integration:
|
|
- Show how to update the existing JavaScript submission handler (using `fetch()`) to send the survey data as JSON to the new Go backend endpoint.
|
|
|
|
Please keep the code minimalist, robust, and well-commented.
|
|
|
|
when everything works, please create a simple docker-compose file that builds the project and runs the container. include traefik labels for reverse proxy routing. |