Projektstart
This commit is contained in:
1
backend/node_modules/@fastify/static/example/public/.hidden/sample.json
generated
vendored
Normal file
1
backend/node_modules/@fastify/static/example/public/.hidden/sample.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"hello": "world"}
|
||||
BIN
backend/node_modules/@fastify/static/example/public/images/sample.jpg
generated
vendored
Normal file
BIN
backend/node_modules/@fastify/static/example/public/images/sample.jpg
generated
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 43 KiB |
9
backend/node_modules/@fastify/static/example/public/index.css
generated
vendored
Normal file
9
backend/node_modules/@fastify/static/example/public/index.css
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
#my-button {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 200px;
|
||||
height: 28px;
|
||||
margin-top: -14px;
|
||||
margin-left: -100px;
|
||||
}
|
||||
11
backend/node_modules/@fastify/static/example/public/index.html
generated
vendored
Normal file
11
backend/node_modules/@fastify/static/example/public/index.html
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="index.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="index.css"></link>
|
||||
</head>
|
||||
<body>
|
||||
<button id="my-button">
|
||||
The button
|
||||
</button>
|
||||
</body>
|
||||
</html>
|
||||
8
backend/node_modules/@fastify/static/example/public/index.js
generated
vendored
Normal file
8
backend/node_modules/@fastify/static/example/public/index.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
window.onload = function () {
|
||||
const b = document.getElementById('my-button')
|
||||
b.onclick = function () {
|
||||
window.alert('foo')
|
||||
}
|
||||
}
|
||||
4
backend/node_modules/@fastify/static/example/public2/test.css
generated
vendored
Normal file
4
backend/node_modules/@fastify/static/example/public2/test.css
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
body {
|
||||
background-color: black;
|
||||
color: white;
|
||||
}
|
||||
8
backend/node_modules/@fastify/static/example/public2/test.html
generated
vendored
Normal file
8
backend/node_modules/@fastify/static/example/public2/test.html
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="test.css"></link>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Test 2</h1>
|
||||
</body>
|
||||
</html>
|
||||
15
backend/node_modules/@fastify/static/example/server-compress.js
generated
vendored
Normal file
15
backend/node_modules/@fastify/static/example/server-compress.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
'use strict'
|
||||
|
||||
const path = require('node:path')
|
||||
const fastify = require('fastify')({ logger: { level: 'trace' } })
|
||||
|
||||
fastify
|
||||
// Compress everything.
|
||||
.register(require('@fastify/compress'), { threshold: 0 })
|
||||
.register(require('../'), {
|
||||
// An absolute path containing static files to serve.
|
||||
root: path.join(__dirname, '/public')
|
||||
})
|
||||
.listen({ port: 3000 }, err => {
|
||||
if (err) throw err
|
||||
})
|
||||
49
backend/node_modules/@fastify/static/example/server-dir-list.js
generated
vendored
Normal file
49
backend/node_modules/@fastify/static/example/server-dir-list.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
'use strict'
|
||||
|
||||
const path = require('node:path')
|
||||
const Handlebars = require('handlebars')
|
||||
|
||||
const fastify = require('fastify')({ logger: { level: 'trace' } })
|
||||
|
||||
// Handlebar template for listing files and directories.
|
||||
const template = `
|
||||
<html>
|
||||
<body>
|
||||
dirs
|
||||
<ul>
|
||||
{{#dirs}}
|
||||
<li><a href="{{href}}">{{name}}</a></li>
|
||||
{{/dirs}}
|
||||
</ul>
|
||||
|
||||
list
|
||||
|
||||
<ul>
|
||||
{{#files}}
|
||||
<li><a href="{{href}}" target="_blank">{{name}}</a></li>
|
||||
{{/files}}
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
const handlebarTemplate = Handlebars.compile(template)
|
||||
|
||||
fastify
|
||||
.register(require('..'), {
|
||||
// An absolute path containing static files to serve.
|
||||
root: path.join(__dirname, '/public'),
|
||||
// Do not append a trailing slash to prefixes.
|
||||
prefixAvoidTrailingSlash: true,
|
||||
// Return a directory listing with a handlebar template.
|
||||
list: {
|
||||
// html or json response? html requires a render method.
|
||||
format: 'html',
|
||||
// A list of filenames that trigger a directory list response.
|
||||
names: ['index', 'index.html', 'index.htm', '/'],
|
||||
// You can provide your own render method as needed.
|
||||
render: (dirs, files) => handlebarTemplate({ dirs, files })
|
||||
}
|
||||
})
|
||||
.listen({ port: 3000 }, err => {
|
||||
if (err) throw err
|
||||
})
|
||||
15
backend/node_modules/@fastify/static/example/server-hidden-file.js
generated
vendored
Normal file
15
backend/node_modules/@fastify/static/example/server-hidden-file.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
'use strict'
|
||||
|
||||
const path = require('node:path')
|
||||
const fastify = require('fastify')({ logger: { level: 'trace' } })
|
||||
|
||||
fastify
|
||||
.register(require('../'), {
|
||||
// An absolute path containing static files to serve.
|
||||
root: path.join(__dirname, '/public'),
|
||||
wildcard: false,
|
||||
serveDotFiles: true
|
||||
})
|
||||
.listen({ port: 3000 }, err => {
|
||||
if (err) throw err
|
||||
})
|
||||
13
backend/node_modules/@fastify/static/example/server.js
generated
vendored
Normal file
13
backend/node_modules/@fastify/static/example/server.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict'
|
||||
|
||||
const path = require('node:path')
|
||||
const fastify = require('fastify')({ logger: { level: 'trace' } })
|
||||
|
||||
fastify
|
||||
.register(require('../'), {
|
||||
// An absolute path containing static files to serve.
|
||||
root: path.join(__dirname, '/public')
|
||||
})
|
||||
.listen({ port: 3000 }, err => {
|
||||
if (err) throw err
|
||||
})
|
||||
Reference in New Issue
Block a user