简体   繁体   中英

Is Single Page Application needs a Application Server?

I'm new to SPA development, so this may be a stupid question. please understand.

My question is "Is SPA(Single Page Application) needs a Application Server?"

As I understand it, the SPA gets the response after calling REST API. It use that response to re-render. If so, is the server that handles REST API "Application Server"?

So many posts say Application Server are tomcat, oracle, etc... and they are also say Application Server handle the request to access the database. Then what is "Application Server" in SPA? or there are no Application Server in SPA? (Are there any architectures or systems I'm not aware of?)

If I'm misunderstanding the architecture, please let me know. I want to understand web server and Application Server in SPA. So I have read many posts but I'm still confused.

Thanks.

A SPA needs one server to serve the SPA bundle to the users browser. If the SPA interacts with an API or APIs, the API(s) could be hosted on the same server that served the SPA bundle, or they could be hosted on other servers.

A Single Page App requires a server to serve the .css , index.html , and .js files it requires. It is not a requirement that that an SPA must communicate with an application server via any means at all.

Your content can be static or self generated by the app itself. Should you require communication with a backend server, you can consume that via some sort of api over protocols such as http, https, websockets or Server Side Events.

To summarize. An SPA can be completely self contained OR access an api to provide functionality. A standalone app requires a server only to serve the component files (.css, .js, .html) of the app itself.

With SPA as well you will have html file and images, js, css files that will be loaded when you launch your single html webpage. So you need to host this static content on some server. So it can be separate web server or same APIs server(Application Server) which can host these static content and serve request for those files. It can be also hosted on cloud static server and distributed via CDN

SPA apps do need to live somewhere.

In the past Ive used anything from:

  • NodeJS code base services running on a Docker container (app & assets being served via express), to
  • dotnetcore on a similar stack (With kestrel server serving the assets running on docker on ec2).
  • Docker container running Apache webserver hosting the statically compiled assets

More recently I've dabbled with compiling the SPA app to a bunch of static assets (such as the ability NextJS / Gatsby provides with their tooling, but there are tons of others or alternatives in other SPA worlds)... but even then you'll need to host those assets somewhere.

  • S3 on Amazon has the ability to host SPA apps "natively" (We're actually doing this exact thing at my current employer)
  • Vercel (This is where I host my personal stuff (also a SPA app), same as S3, just another provider)

Again it's all up to you, but yes, you still need to make the JavaScript available somehow, you just need to pick your mechanic. PaaS with a baked in WebServer such as Vercel or AWS provides, or go totally custom.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM