Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config.files.static -> config.files.assets #258

Merged
merged 2 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/hot-keys-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Fix handling of static files
2 changes: 1 addition & 1 deletion packages/adapter-node/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const noop_handler = (_req, _res, next) => next();

// TODO how to handle the case where `paths.assets !== ''` and `paths.generated !== '/app'`?
// Does that even make sense in the context of adapter-node?
const static_handler = fs.existsSync(app.files.static) ? mutable(app.files.static) : noop_handler;
const static_handler = fs.existsSync(app.files.assets) ? mutable(app.files.assets) : noop_handler;
const prerendered_handler = fs.existsSync('build/prerendered')
? mutable('build/prerendered')
: noop_handler;
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/api/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export async function build(config) {

export function render(request, { paths = ${s(config.paths)}, only_prerender = false } = {}) {
return renderer.render(request, {
static_dir: ${s(config.files.static)},
static_dir: ${s(config.files.assets)},
paths,
template,
manifest,
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/api/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Watcher extends EventEmitter {
);
set_paths(this.config.paths);

const static_handler = sirv(this.config.files.static, {
const static_handler = sirv(this.config.files.assets, {
dev: true
});

Expand Down Expand Up @@ -184,7 +184,7 @@ class Watcher extends EventEmitter {
body
},
{
static_dir: this.config.files.static,
static_dir: this.config.files.assets,
paths: this.config.paths,
template: ({ head, body }) =>
template.replace('%svelte.head%', () => head).replace('%svelte.body%', () => body),
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/api/start/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export function start({ port, config }) {
return new Promise((fulfil) => {
const app = relative('./.svelte/build/optimized/server/app.js');

const static_handler = fs.existsSync(config.files.static)
? mutable(config.files.static)
const static_handler = fs.existsSync(config.files.assets)
? mutable(config.files.assets)
: (_req, _res, next) => next();

const assets_handler = sirv('.svelte/build/optimized/client', {
Expand Down
11 changes: 10 additions & 1 deletion test/apps/basics/test/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import path from 'path';
import glob from 'tiny-glob/sync';
import { runner } from '../../../runner' // TODO make this a package?
import * as assert from 'uvu/assert';
import { runner } from '../../../runner'; // TODO make this a package?

runner((test, is_dev) => {
const cwd = path.join(__dirname, '../src/routes');
const modules = glob('**/__tests__.js', { cwd });
for (const module of modules) {
require(`../src/routes/${module}`).default(test, is_dev);
}

test('static files', async ({ fetch }) => {
let res = await fetch('/static.json');
assert.equal(await res.json(), 'static file');

res = await fetch('/subdirectory/static.json');
assert.equal(await res.json(), 'subdirectory file');
});
});