Code Monkey home page Code Monkey logo

Comments (4)

Atinux avatar Atinux commented on April 28, 2024 2

Hi @nodegin

Next.js is (from their README):

A minimalistic framework for server-rendered React applications

I don't think it fit it's purpose to add any middleware or API inside since it's made to create an isomorphic application. You API should be on another server (made with Express for example).

from next.js.

malixsys avatar malixsys commented on April 28, 2024 1

+1 on /api

from next.js.

Twipped avatar Twipped commented on April 28, 2024

This post seems related to my question. I don't see any way for a next app to handle POST data or ajax requests. If you have to create a separate app to act as an api just to receive writes, that makes a lot of simple projects much more time consuming.

There also doesn't seem to be any way to setup user sessions.

A method to attach an express router above the page router would probably cover all these needs. Any middleware attached to that Router would affect the request/response objects for everything else. You could then attach ajax and post routes to that router and either redirect to get routes or call next('route') to let the request bubble down to the page router.

edit: I see now that Next isn't using express internally, so the request couldn't bubble down. However it looks like it would be fairly easy to add a step to server/index.js#run that invokes an express app with the req/res objects and then checks if a response was sent before invoking the Next router. That doesn't address the need for sessions, however.

from next.js.

timneutkens avatar timneutkens commented on April 28, 2024

@nodegin I guess this can be closed since 2.0.0 is going to include the programmatic api.

from next.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.