Skip to main content

Urls

This section covers all function that could be used to generate a url.

Setting base url

To make any of the incoming functions work, make sure to add in your .env file the following:

BASE_URL=http://localhost:3000

Then to import it in the App configurations.

Get url path

To generate a full url for a given path, use the url function.

src/main.ts
import { url } from "@warlock.js/core";

console.log(url("posts")); // returns http://localhost:3000/posts

Get public url

To generate a full url for a given path, use the publicUrl function, it will generate a url with the public path.

src/main.ts
import { publicUrl } from "@warlock.js/core";

console.log(publicUrl("images")); // returns http://localhost:3000/public/images

Uploads url

To generate a full url for a given path, use the uploadsUrl function, it will generate a url with the uploads path.

src/main.ts
import { uploadsUrl } from "@warlock.js/core";

console.log(uploadsUrl("images")); // returns http://localhost:3000/uploads/images