25 lines
785 B
TypeScript
25 lines
785 B
TypeScript
import { getBaseUrl, getSourceUrl } from './src/url_utils.ts'
|
|
import { toUser, toUserDomain } from './src/user_utils.ts'
|
|
import { serveFile } from './src/serve_file.ts'
|
|
|
|
Deno.serve({ port: Number(Deno.env.get('PORT') ?? 8000) }, async (req) => {
|
|
const reqUrl = new URL(req.url)
|
|
|
|
// Get and check user-domain and user-login
|
|
const rawUserDomain = reqUrl.hostname.split('.')[0]
|
|
const userDomain = toUserDomain(rawUserDomain)
|
|
const user = toUser(userDomain)
|
|
|
|
console.log(`Getting portfolio of > @${user}`)
|
|
|
|
// Get relative source path
|
|
const filePath = `.${reqUrl.pathname}`
|
|
|
|
// Get source base url ("/dist" if available, "/" else)
|
|
const baseUrl = await getBaseUrl(user)
|
|
const fileUrl = getSourceUrl(filePath, baseUrl)
|
|
|
|
// Get source and mime type
|
|
return serveFile(fileUrl)
|
|
})
|