The "http" app runs the web server and provides a simple HTTP service for frontend Javascript.
The default configuration for the "http" app looks like this:
module.exports = {
// host to listen on
host: process.env.SERVER_HOST || 'localhost',
// port to listen on
port: process.env.SERVER_PORT || 8080
};
You can publish the default configuration for the "http" service to
config/http.js
using the following command:
node . publish --config http
You can use that to edit server configuration.
The "http" app publishes an ApiSvc
for frontend use. You can publish
all source files using the following command:
node . publish --src http
The file src/http/services/api.svc.js
will be created. It is a single wrapper
around an axios instance which uses a
meta tag (which is created in default templates published by the "assets" app)
to get the baseUrl for the mount point of the current app. This allows you to
write http calls without knowing where your app's router might be mounted.
It exposes the methods get
and post
, and you can also get the axios
instance.
// src/my_custom_app/lib.js
import { ApiSvc } from '../http/services/api.svc';
async function getSomething() {
// if you app's router is mounted to /custom and the assets base template
// is used, the call will go to /custom/api/something
let resData = await ApiSvc.get('/api/something');
let postResponseData = await Api.post('/api/something', {});
}
You can run the HTTP server which includes all your mounted routers using the following NPM command:
npm start