Also if the node style APIs aren't your thing, this can easily be done in
the weblit framework.

https://github.com/creationix/weblit

In weblit, end is automatic when you return from a coroutine.  Setting the
response code is as simple as `res.code = 302` and adding a header is
`res.headers.Location = newUrl`.

Weblit uses coroutines instead of callbacks which is much more lua
friendly.  The Luvit APIs are for people coming from node.js who already
know that system.  If you're starting new, I recommend coroutine style for
luvit code.

I plan on writing a blog post soon explaining how to make a web app start
to finish using the new style.

-Tim Caswell


On Fri, Feb 5, 2016 at 12:35 PM, Paul Reilly <[email protected]> wrote:

> Thanks, the last one works without errors (no idea how I didn't see
> finish() in the API and relate it to end() :) ). It doesn't redirect Chrome
> or Firefox though. I'll have a play around and see if I can work out why.
>
>
> On Thursday, 4 February 2016 00:00:48 UTC, Ryan Phillips wrote:
>
>> Hey All,
>>
>> Paul, you will want to do something like:
>>
>> res:writeHead(302, {Location = 'somepath'})
>> res:finish()
>>
>> Regards,
>> Ryan
>>
>> On Wed, Feb 3, 2016, at 03:43 PM, Michal Kolodziejczyk GMAIL wrote:
>>
>>
>> Hello,
>> as far as Lua goes, the correct syntax would be:
>> res['end']()
>>
>> I think that "POST redirect" depends on browser support. I do remember
>> many years ago some browsers did redirect to the new location, but the
>> POST content was not resent (so it was effectively redirecting original
>> POST request to the new GET request).
>> I have not tested it lately.
>>
>> Regards.
>> miko
>>
>> On 03.02.2016 23:36, Paul Reilly wrote:
>>
>> Thanks very much for the reply. Unfortunately end is a keyword in Lua
>> and it looks from the API that an alternative has not been
>> implemented. writeHead(302...) without an end hangs the page loading
>> so that won't work by itself.
>>
>> I have it serving up a new page depending on POST data, but the URL is
>> not updating in the browser I assume because it isn't redirected. It
>> would be interesting to hear what the correct procedure is for this.
>>
>> On Tuesday, 2 February 2016 23:09:54 UTC, alfred wrote:
>>
>>   res.writeHead(302, {Location = root..req.uri.pathname})
>>   res.end()
>>
>>   Will this work?
>>
>>
>>   On Tuesday, 2 February 2016 04:50:52 UTC+8, Paul Reilly wrote:
>>
>>       Hi
>>
>>       I am beginning to play with Luvit and have one stumbling block
>>       left to finish an app, which is to redirect after receiving
>>       POST data. I am receiving the data fine, but don't know how to
>>       redirect it? Could somebody give me a nudge in the right
>>       direction?
>>
>>       In http.createServer I have...
>>
>>           if req.method=="POST" then
>>           local b={}
>>           print("request is POST")
>>           req:on("data", function(chunk)
>>             if #chunk>100 then
>>               return
>>             else
>>               table.insert(b,chunk)
>>             end
>>           end)
>>
>>           req:on("end", function ()
>>               if #b>0 then
>>                 req.uri.pathname=processPOST(b,req.uri.pathname)
>>                 --res.send({redirect=root..req.uri.pathname})
>>                 --req.redirect(req.uri.pathname)
>>                 --req:redirect(req.uri.pathname)
>>               end
>>           end)
>>
>>       Thanks for any advice,
>>
>>       Cheers
>>
>>       Paul
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "luvit" group.
>> To unsubscribe from this group and stop receiving emails from it, send
>> an email to [email protected]
>> <mailto:[email protected]>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "luvit" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "luvit" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"luvit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to