Skip to main content

Serve application from local server

info

For better context, learn more about the following JS APIs:

Tizen CoreApp (v2.12.x and above) includes a local HTTP server running on http://localhost:10081/ that can serve files from the device's internal storage. This is a specialty feature designed for a use case of serving third-party SPAs that use absolute paths (e.g., /assets/app.js, /content/page.html) which cannot be loaded directly from the filesystem.

When do you need this?

Most offline content can be handled with sos.offline.cache or sos.fileSystem — those APIs cache files and return local file paths that work directly in <img>, <video>, or <iframe> tags. You only need the local server when a third-party web application uses absolute-path references that must resolve against a real HTTP origin.

info

The local server is only accessible from the device itself (localhost). Other devices on the same network cannot reach it.

File storage and URL mapping

To make files available on the local server, save them under the data/localServer path prefix using sos.fileSystem. The directory structure maps directly to the URL path:

Saved to sos.fileSystem pathAccessible at
data/localServer/index.htmlhttp://localhost:10081/index.html
data/localServer/assets/styles.csshttp://localhost:10081/assets/styles.css
data/localServer/assets/bundle.jshttp://localhost:10081/assets/bundle.js

Because the HTML uses absolute-path references (e.g., /assets/styles.css), the browser resolves them against localhost:10081 and loads everything from disk — no URL rewriting is needed.

warning

The data/localServer prefix is required for sos.fileSystem to place files in the correct directory. Do not change this prefix.

Supported file types

The local server automatically sets the correct Content-Type header based on the file extension:

ExtensionContent-Type
.htmltext/html; charset=utf-8
.jsonapplication/json; charset=utf-8
.jsapplication/javascript; charset=utf-8
.csstext/css; charset=utf-8
.svgimage/svg+xml
.pngimage/png
.jpg, .jpegimage/jpeg
.mp4video/mpeg
.webpimage/webp
.woff2font/woff2
.wofffont/woff

Workflow

A typical pattern for deploying a third-party SPA offline:

Because all assets are served from the device's internal storage, the application continues to work even when the device loses its internet connection.