-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
404 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,24 @@ | ||
#!/usr/bin/env node | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
import express from 'express'; | ||
import Fastify from 'fastify'; | ||
import fastifyStatic from '@fastify/static'; | ||
|
||
export default function serveStatic(staticPath, rootURL = 'mosaic/index.html', port = 3000) { | ||
function loadPage(res, fullPath) { | ||
const extension = path.extname(fullPath) || 'html'; | ||
if (extension !== 'html') { | ||
return; | ||
export default async function serveStatic(staticPath, port) { | ||
const start = async () => { | ||
try { | ||
await server.listen({ port }); | ||
console.log(`[Mosaic] Listening on port ${port}`); | ||
} catch (err) { | ||
server.log.error(err); | ||
process.exit(1); | ||
} | ||
const fsPath = `${fullPath}.${extension}`; | ||
fs.access(fsPath, fs.constants.F_OK, err => { | ||
if (err) { | ||
res.sendFile(path.join(staticPath, `404.html`)); | ||
} else { | ||
res.sendFile(fsPath); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
const server = express(); | ||
server.use(express.static(staticPath)); | ||
server.get(/^\/$/, (_req, res) => { | ||
loadPage(res, path.join(staticPath, rootURL)); | ||
const server = Fastify(); | ||
await server.register(fastifyStatic, { | ||
root: staticPath | ||
}); | ||
server.get(`*`, (req, res) => { | ||
loadPage(res, path.join(staticPath, req.path)); | ||
server.setNotFoundHandler((_request, reply) => { | ||
reply.sendFile(`404.html`); | ||
}); | ||
server.listen(port, () => console.log(`Server is listening on port ${port}`)); | ||
await start(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[{"title":"Mosaic","route":"/mosaic/index"},{"title":"Aliases","route":"/mosaic/author/aliases"},{"title":"Fragments","route":"/mosaic/author/fragments"},{"title":"Frontmatter","route":"/mosaic/author/frontmatter"},{"title":"Author","route":"/mosaic/author/index"},{"title":"Markdown Syntax","route":"/mosaic/author/markdown-syntax"},{"title":"Page Templates","route":"/mosaic/author/page-templates"},{"title":"Refs","route":"/mosaic/author/refs"},{"title":"UI Components","route":"/mosaic/author/ui-components"},{"title":"Configure","route":"/mosaic/configure/index"},{"title":"Content Fragment","route":"/mosaic/fragments/content-fragment"},{"title":"Fragments","route":"/mosaic/fragments/index"},{"title":"Tile A","route":"/mosaic/fragments/tile-a"},{"title":"Tile B","route":"/mosaic/fragments/tile-b"},{"title":"Create a Site","route":"/mosaic/getting-started/create-a-site"},{"title":"Getting Started","route":"/mosaic/getting-started/index"},{"title":"Publish a site to AWS","route":"/mosaic/getting-started/publish-site-to-aws"},{"title":"Publish","route":"/mosaic/publish/index"},{"title":"Publish a site to AWS","route":"/mosaic/publish/publish-site-to-aws"},{"title":"Publish a site to Vercel","route":"/mosaic/publish/publish-site-to-vercel"},{"title":"Test","route":"/mosaic/test/index"},{"title":"Admin","route":"/mosaic/configure/admin/index"},{"title":"Layouts","route":"/mosaic/configure/layouts/index"},{"title":"Active mode","route":"/mosaic/configure/modes/active"},{"title":"Modes of operation","route":"/mosaic/configure/modes/index"},{"title":"Snapshot file mode","route":"/mosaic/configure/modes/snapshot-file"},{"title":"Snapshot AWS/S3 mode","route":"/mosaic/configure/modes/snapshot-s3"},{"title":"$afterSource","route":"/mosaic/configure/plugins/after-source"},{"title":"afterUpdate","route":"/mosaic/configure/plugins/after-update"},{"title":"$beforeSend","route":"/mosaic/configure/plugins/before-send"},{"title":"Plugins","route":"/mosaic/configure/plugins/index"},{"title":"shouldClearCache","route":"/mosaic/configure/plugins/should-clear-cache"},{"title":"Git Repo Source","route":"/mosaic/configure/sources/git-repo-source"},{"title":"HTTP Source","route":"/mosaic/configure/sources/http-source"},{"title":"Sources","route":"/mosaic/configure/sources/index"},{"title":"Local Folder Source","route":"/mosaic/configure/sources/local-folder-source"},{"title":"Source Schedules","route":"/mosaic/configure/sources/schedules"},{"title":"Custom Components","route":"/mosaic/configure/theme/custom-components"},{"title":"Custom CSS","route":"/mosaic/configure/theme/custom-css"},{"title":"Theming Your Site","route":"/mosaic/configure/theme/index"},{"title":"Aliases Test","route":"/mosaic/test/aliases/index"},{"title":"Detail Highlight Test Page","route":"/mosaic/test/layouts/detail-highlight"},{"title":"Detail Overview Test Page","route":"/mosaic/test/layouts/detail-overview"},{"title":"Detail Technical Test Page","route":"/mosaic/test/layouts/detail-technical"},{"title":"Edit Layout","route":"/mosaic/test/layouts/edit"},{"title":"Full Width Layout","route":"/mosaic/test/layouts/full-width"},{"title":"Layouts","route":"/mosaic/test/layouts/index"},{"title":"Landing Layout Test Page","route":"/mosaic/test/layouts/landing"},{"title":"Newsletter Test Page","route":"/mosaic/test/layouts/newsletter"},{"title":"Product Discover Test Page","route":"/mosaic/test/layouts/product-discover"},{"title":"Product Preview Test Page","route":"/mosaic/test/layouts/product-preview"},{"title":"Refs Data","route":"/mosaic/test/refs/data"},{"title":"Refs Test","route":"/mosaic/test/refs/index"}] | ||
[{"title":"Mosaic","route":"/mosaic/index"},{"title":"Aliases","route":"/mosaic/author/aliases"},{"title":"Fragments","route":"/mosaic/author/fragments"},{"title":"Frontmatter","route":"/mosaic/author/frontmatter"},{"title":"Author","route":"/mosaic/author/index"},{"title":"Markdown Syntax","route":"/mosaic/author/markdown-syntax"},{"title":"Page Templates","route":"/mosaic/author/page-templates"},{"title":"Refs","route":"/mosaic/author/refs"},{"title":"UI Components","route":"/mosaic/author/ui-components"},{"title":"Configure","route":"/mosaic/configure/index"},{"title":"Content Fragment","route":"/mosaic/fragments/content-fragment"},{"title":"Fragments","route":"/mosaic/fragments/index"},{"title":"Tile A","route":"/mosaic/fragments/tile-a"},{"title":"Tile B","route":"/mosaic/fragments/tile-b"},{"title":"Create a Site","route":"/mosaic/getting-started/create-a-site"},{"title":"Getting Started","route":"/mosaic/getting-started/index"},{"title":"Publish a site to AWS","route":"/mosaic/getting-started/publish-site-to-aws"},{"title":"Publish","route":"/mosaic/publish/index"},{"title":"Publish a site to AWS","route":"/mosaic/publish/publish-site-to-aws"},{"title":"Publish a site to Vercel","route":"/mosaic/publish/publish-site-to-vercel"},{"title":"Test","route":"/mosaic/test/index"},{"title":"Admin","route":"/mosaic/configure/admin/index"},{"title":"Detail Highlight","route":"/mosaic/configure/layouts/detail-highlight"},{"title":"Detail Overview","route":"/mosaic/configure/layouts/detail-overview"},{"title":"Detail Technical","route":"/mosaic/configure/layouts/detail-technical"},{"title":"Layouts","route":"/mosaic/configure/layouts/index"},{"title":"Landing Layout","route":"/mosaic/configure/layouts/landing"},{"title":"Product Discover Layout","route":"/mosaic/configure/layouts/product-discover"},{"title":"Product Preview Layout","route":"/mosaic/configure/layouts/product-preview"},{"title":"Active mode","route":"/mosaic/configure/modes/active"},{"title":"Modes of operation","route":"/mosaic/configure/modes/index"},{"title":"Snapshot file mode","route":"/mosaic/configure/modes/snapshot-file"},{"title":"Snapshot AWS/S3 mode","route":"/mosaic/configure/modes/snapshot-s3"},{"title":"$AliasPlugin","route":"/mosaic/configure/plugins/alias-plugin"},{"title":"BreadcrumbsPlugin","route":"/mosaic/configure/plugins/breadcrumbs-plugin"},{"title":"BrokenLinksPlugin","route":"/mosaic/configure/plugins/broken-links-plugin"},{"title":"$CodeModPlugin","route":"/mosaic/configure/plugins/codemod-plugin"},{"title":"Plugins","route":"/mosaic/configure/plugins/index"},{"title":"LazyPagePlugin","route":"/mosaic/configure/plugins/lazy-page-plugin"},{"title":"PagesWithoutFileExtPlugin","route":"/mosaic/configure/plugins/pages-wthout-extensions-plugin"},{"title":"PublicAssetsPlugin","route":"/mosaic/configure/plugins/public-assets-plugin"},{"title":"ReadingTimePlugin","route":"/mosaic/configure/plugins/reading-time-plugin"},{"title":"$RefPlugin","route":"/mosaic/configure/plugins/ref-plugin"},{"title":"SearchIndexPlugin","route":"/mosaic/configure/plugins/search-index-plugin"},{"title":"SharedConfigPlugin","route":"/mosaic/configure/plugins/shared-config-plugin"},{"title":"SidebarPlugin","route":"/mosaic/configure/plugins/sidebar-plugin"},{"title":"SiteMapPlugin","route":"/mosaic/configure/plugins/site-map-plugin"},{"title":"$TagPlugin","route":"/mosaic/configure/plugins/tag-plugin"},{"title":"TableOfContentsPlugin","route":"/mosaic/configure/plugins/toc-plugin"},{"title":"Git Repo Source","route":"/mosaic/configure/sources/git-repo-source"},{"title":"HTTP Source","route":"/mosaic/configure/sources/http-source"},{"title":"Sources","route":"/mosaic/configure/sources/index"},{"title":"Local Folder Source","route":"/mosaic/configure/sources/local-folder-source"},{"title":"Source Schedules","route":"/mosaic/configure/sources/schedules"},{"title":"Custom Components","route":"/mosaic/configure/theme/custom-components"},{"title":"Custom CSS","route":"/mosaic/configure/theme/custom-css"},{"title":"Theming Your Site","route":"/mosaic/configure/theme/index"},{"title":"Aliases Test","route":"/mosaic/test/aliases/index"},{"title":"Detail Highlight Test Page","route":"/mosaic/test/layouts/detail-highlight"},{"title":"Detail Overview Test Page","route":"/mosaic/test/layouts/detail-overview"},{"title":"Detail Technical Test Page","route":"/mosaic/test/layouts/detail-technical"},{"title":"Edit Layout","route":"/mosaic/test/layouts/edit"},{"title":"Full Width Layout","route":"/mosaic/test/layouts/full-width"},{"title":"Layouts","route":"/mosaic/test/layouts/index"},{"title":"Landing Layout Test Page","route":"/mosaic/test/layouts/landing"},{"title":"Newsletter Test Page","route":"/mosaic/test/layouts/newsletter"},{"title":"Product Discover Test Page","route":"/mosaic/test/layouts/product-discover"},{"title":"Product Preview Test Page","route":"/mosaic/test/layouts/product-preview"},{"title":"Refs Data","route":"/mosaic/test/refs/data"},{"title":"Refs Test","route":"/mosaic/test/refs/index"},{"title":"$afterSource","route":"/mosaic/configure/plugins/lifecycle/after-source"},{"title":"afterUpdate","route":"/mosaic/configure/plugins/lifecycle/after-update"},{"title":"$beforeSend","route":"/mosaic/configure/plugins/lifecycle/before-send"},{"title":"Lifecycle Events","route":"/mosaic/configure/plugins/lifecycle/index"},{"title":"shouldClearCache","route":"/mosaic/configure/plugins/lifecycle/should-clear-cache"},{"title":"shouldUpdateNamespaceSources","route":"/mosaic/configure/plugins/lifecycle/should-update-namespace-sources"}] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.