Skip to content

Commit

Permalink
fix: Add favicon to app.yaml (#68)
Browse files Browse the repository at this point in the history
Add assets such as favicon and robot.txt to app yaml to app.yaml as static assets, making sure they get handled by cloud storage instead of appengine
  • Loading branch information
HalfdanJ authored Feb 4, 2023
1 parent 0dcc8a7 commit 25ddfc2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import esbuild from 'esbuild';

const files = fileURLToPath(new URL('files', import.meta.url));

/** @type {import('.')} **/
/** @type {import('.').default} **/
export default function entrypoint(options = {}) {
const {out = 'build', external = [], useCloudLogging = true, dependencies = {}} = options;

Expand All @@ -20,8 +20,8 @@ export default function entrypoint(options = {}) {
builder.rimraf(temporary);

builder.log.minor('Copying assets');
builder.writeClient(`${out}/storage${builder.config.kit.paths.base}`);
builder.writePrerendered(`${out}/storage${builder.config.kit.paths.base}`);
const clientFiles = builder.writeClient(`${out}/storage${builder.config.kit.paths.base}`);

const relativePath = posix.relative(temporary, builder.getServerDirectory());

Expand Down Expand Up @@ -87,6 +87,17 @@ export default function entrypoint(options = {}) {
script: 'auto',
}));

// Add yaml entries for all files outside _app directory, such as favicons
const additionalClientAssets = clientFiles
.filter(file => !file.startsWith('_app/'))
.map(file => ({
url: '/' + file,
// eslint-disable-next-line camelcase
static_files: join('storage', file),
upload: join('storage', file),
secure: 'always',
}));

// Load existing app.yaml if it exists
let yaml = {};
if (existsSync('app.yaml')) {
Expand All @@ -99,6 +110,7 @@ export default function entrypoint(options = {}) {
...prerenderedPages,
...prerenderedRedirects,
...prerenderedAssets,
...additionalClientAssets,
{
url: `/${builder.config.kit.appDir}/immutable/`,
// eslint-disable-next-line camelcase
Expand Down
8 changes: 8 additions & 0 deletions tests/expected_app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ handlers:
upload: storage/test.json
secure: always
mime_type: application/json
- url: /favicon.png
static_files: storage/favicon.png
upload: storage/favicon.png
secure: always
- url: /robots.txt
static_files: storage/robots.txt
upload: storage/robots.txt
secure: always
- url: /_app/immutable/
static_dir: storage/_app/immutable
expiration: 30d 0h
Expand Down

0 comments on commit 25ddfc2

Please sign in to comment.