Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

remko/base-uri

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Returns the base URI where your application is running. This allows you to create applications that can be deployed at any sub-uri (e.g. with Passenger Phusion), without needing to hard code the path in your application.

In a Node environment, looks at PASSENGER_BASE_URI if it is present, and otherwise defaults to /.

In a browser environment, looks at the location of the executing script, and takes the dirname of this. This assumes that your script is always located at the top of your application.

Installation

npm install base-uri --save

Usage

General

var baseURI = require('base-uri');

Express

Use the base URI to determine at which point to mount all your routes.

var app = express();
var baseURI = require('base-uri');

// Create all your routes
var router = express.Router();
router.get('/', function (req, res) {
    res.send('Hello world');
});

// Mount the routes at the base URI
app.use(baseURI, router);

Browser

Use the base URI to create internal application links.

var baseURI = require('base-uri');
var $ = require('jquery');

$('body').append('<a href="' + baseURI + '/somewhere">Link</a>');

or with ES6

import baseURI from 'base-uri';
import $ from 'jquery';

$('body').append(`<a href='${baseURI}/somewhere'>Link</a>`));

About

Get the base URI of client or server applications

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published