Skip to content

Commit

Permalink
Feature/eng 898 blockless sites should serve any index file from the …
Browse files Browse the repository at this point in the history
…root (#100)
  • Loading branch information
uditdc authored Jun 29, 2023
1 parent a4b930b commit 422c2b1
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/commands/sites/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,38 @@ const generateCompileDirectory = (source: string): { dir: string, file: string }
let status: u32 = 404
let contentType: string = 'text/html'
if (req.url === '/' && assets.has('/index.html')) {
req.url = '/index.html'
let url = req.url
let urlWithoutSlash = url.endsWith('/') ? url.slice(0, -1) : url
// Serve the index file for the homepage
if (url === '/' && assets.has('/index.html')) {
url = '/index.html'
}
if (!assets.has(req.url) && assets.has(req.url + '.html')) {
req.url = req.url + '.html'
// Serve nested index.html for any folder route
// Serve matching html for a non html route
if (!assets.has(urlWithoutSlash) && assets.has(urlWithoutSlash + '/index.html')) {
url = urlWithoutSlash + '/index.html'
} else if (!assets.has(urlWithoutSlash) && assets.has(urlWithoutSlash + '.html')) {
url = urlWithoutSlash + '.html'
}
if (assets.has(req.url)) {
// Match assets and serve data
if (assets.has(url)) {
// Parse content type and format
const content = assets.get(req.url) || '404 not found'
const content = assets.get(url)
if (content.startsWith('data:')) {
const matchString = content.replace('data:', '')
const matchTypeSplit = matchString.split(';')
contentType = matchTypeSplit[0]
response = matchTypeSplit[1]
}
response = assets.get(req.url) || '404 not found'
response = assets.get(url)
status = 200
} else if (assets.has('/404.html')) {
response = assets.get('/404.html')
}
return new http.Response(response)
Expand Down

0 comments on commit 422c2b1

Please sign in to comment.