diff --git a/fallback.html b/fallback.html new file mode 100644 index 0000000..8c0dcbb --- /dev/null +++ b/fallback.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/core/create_routes.ts b/src/core/create_routes.ts index ec6df9b..06728d9 100644 --- a/src/core/create_routes.ts +++ b/src/core/create_routes.ts @@ -3,6 +3,11 @@ import * as path from 'path'; import { locations } from '../config'; import { Page, PageComponent, ServerRoute } from '../interfaces'; +const fallback_index = path.resolve( + __dirname, + '../fallback.html' +); + export default function create_routes(cwd = locations.routes()) { const components: PageComponent[] = []; const pages: Page[] = []; @@ -90,7 +95,7 @@ export default function create_routes(cwd = locations.routes()) { params.push(...item.parts.filter(p => p.dynamic).map(p => p.content)); if (item.is_dir) { - const index = path.join(dir, 'index.html'); + const index = path.join(dir, item.basename, 'index.html'); const component = fs.existsSync(index) ? { name: `page_${get_slug(item.file)}`, @@ -105,7 +110,10 @@ export default function create_routes(cwd = locations.routes()) { segments, params, stack.concat({ - component, + component: component || { + name: 'fallback', + file: fallback_index + }, params }) ); diff --git a/src/middleware.ts b/src/middleware.ts index 5527745..102d06a 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -358,8 +358,6 @@ function get_page_handler(routes: RouteObject, store_getter: (req: Req) => Store store: store && try_serialize(store.get()) }; - console.log(serialized.preloaded); - const data = Object.assign({}, props, { params: req.params }, { child: {} }); diff --git a/test/unit/create_routes/index.js b/test/unit/create_routes/index.js index 4b37bd3..d8bd45f 100644 --- a/test/unit/create_routes/index.js +++ b/test/unit/create_routes/index.js @@ -2,7 +2,7 @@ const path = require('path'); const assert = require('assert'); const { create_routes } = require('../../../dist/core.ts.js'); -describe.only('create_routes', () => { +describe('create_routes', () => { it('creates routes', () => { const { components, pages, server_routes } = create_routes(path.join(__dirname, 'samples/basic'));