Skip to content

Commit

Permalink
add register_dns handler
Browse files Browse the repository at this point in the history
  • Loading branch information
yyamada12 committed Nov 25, 2023
1 parent 14bceb4 commit e4f3848
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
4 changes: 0 additions & 4 deletions etc/nginx/nginx.conf
Expand Up @@ -117,10 +117,6 @@ http {
location / {
try_files $uri /index.html;
}
location /api/register {
proxy_set_header Host $host;
proxy_pass http://localhost:8080;
}
location /api {
proxy_set_header Host $host;
proxy_pass http://192.168.0.11:8080;
Expand Down
1 change: 1 addition & 0 deletions webapp/go/main.go
Expand Up @@ -437,6 +437,7 @@ func main() {

// user
e.POST("/api/register", registerHandler)
e.POST("/api/register_dns", registerDNSHandler)
e.POST("/api/login", loginHandler)
e.GET("/api/user/me", getMeHandler)
// フロントエンドで、配信予約のコラボレーターを指定する際に必要
Expand Down
18 changes: 18 additions & 0 deletions webapp/go/user_handler.go
Expand Up @@ -317,6 +317,24 @@ func registerHandler(c echo.Context) error {
return c.JSON(http.StatusCreated, user)
}

// ユーザ登録API
// POST /api/register_dns
func registerDNSHandler(c echo.Context) error {

defer c.Request().Body.Close()

req := PostUserRequest{}
if err := json.NewDecoder(c.Request().Body).Decode(&req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "failed to decode the request body as json")
}

if out, err := exec.Command("pdnsutil", "add-record", "u.isucon.dev", req.Name, "A", "0", powerDNSSubdomainAddress).CombinedOutput(); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, string(out)+": "+err.Error())
}

return c.NoContent(http.StatusOK)
}

// ユーザログインAPI
// POST /api/login
func loginHandler(c echo.Context) error {
Expand Down

0 comments on commit e4f3848

Please sign in to comment.