Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

GH-371 Added initial public files doc #372

Open
wants to merge 2 commits into
base: 4.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions 06-Digging-Deeper/05-Public-Files.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: Public Files
permalink: public-files
category: digging-deeper
---

= Public Files

toc::[]

AdonisJS can serve static assets and public files

NOTE: It would be better to use CDN or reverse proxy like Nginx / Apache etc to serve static files
McSneaky marked this conversation as resolved.
Show resolved Hide resolved

== Setup

To serve public files `'Adonis/Middleware/Static',` server middleware must be enabled in `start/kernel.js`
McSneaky marked this conversation as resolved.
Show resolved Hide resolved

.start/kernel.js
[source, js]
----
const serverMiddleware = [
'Adonis/Middleware/Static',
]
----

All files in `public` folder will be served as static files

== Config
Static files configuration is in `config/app.js` and accepts the following options.

=== dotfiles
Define how to treat dot files when trying to server static resources.

You can return one of the following values:

[ul-spaced]
- "ignore" - will ignore dot files and throw not found 404 error
- "deny" - will deny access to dot files and throw forbidden 403 error
- "allow" - will allow access to dot files

=== etag
Enable or disable etag header generation

It can be set to boolean `true` or `false`


=== extensions
Set file extension fallbacks.

When set, if a file is not found, the given
extensions will be added to the file name and search for. The first
that exists will be served

It can be set to array of strings.

Example value: ['html', 'htm']

When there is file `hello-world.html` inside `public` folder visiting http://localhost:3333/hello-world would return `hello-world.html`