0

I am a new aspiring software developer (currently network engineer/sysadmin) treating Vlang as my first and hopefully main language of choice. I am trying to build an API gateway for pocketbase. This is my current code, i want the user to visit /login and then be forwarded to the pocketbase admin instance

module main

import nedpals.vex.server
import nedpals.vex.ctx
import nedpals.vex.router
import net.http

fn main() {
    mut app := router.new()
     app.route(.get, '/', fn (req &ctx.Req, mut res ctx.Resp) {
                http.get('http://localhost:8090/_/#/login') or {}
    })
     app.route(.get, '/users/:name', fn (req &ctx.Req, mut res ctx.Resp) {
        println('path is ${req.params["name"]}')
    }, fn (req &ctx.Req, mut res ctx.Resp) {
        http.get('path: ' + req.params['name']) or {resp.body}
    })

The above code is not working

I tried looking online for some simple examples but i could not find any. Can someone more experienced assist here?

Thanks

Aimable

  • Please describe what you mean by "not working". Is there an error message? Does the forward you described not occur? – AdamExchange Oct 27 '22 at 04:42
  • Thank you Adam. In fact i am trying to receive a request on vweb and forward that request to another server listening to a different port as above, then return the second server's response to the initial user (i think it is called middleware or gateway). When i open vweb's address i don't see any error but i dont receive any data – Habiyakare Aimable Oct 28 '22 at 16:12
  • As already mentioned. Proper error-message is required. `http.get('http://localhost:8090/_/#/login') or {}` won't redirect/forward. You need to use `.redirect()` . Since you're using vex it should be `res.redirect('http://localhost:8090/_/...')` – V-Light Jul 09 '23 at 21:01

0 Answers0