Verified Commit ad151433 authored by doshitan's avatar doshitan

Add .well-known pages for Matrix

Also update lambda to allow cross-origin access to matrix client config.
parent a818affe
{
"m.homeserver": { "base_url": "https://matrix.doshitan.com" },
"m.identity_server": { "base_url": "https://vector.im" }
}
{
"m.server": "matrix.doshitan.com:443"
}
......@@ -39,8 +39,11 @@ main = do
version "redirects" $ createRedirects redirects
match "raw/**" $ do
route $ gsubRoute "raw/" (const "")
match ("raw/**") $ do
route $ composeRoutes' [ gsubRoute "raw/" (const "")
-- hakyll patterns don't like hidden directories
, gsubRoute "well-known" (const ".well-known")
]
compile copyFileCompiler
match "assets/img/favicon.ico" $ do
......
......@@ -6,12 +6,12 @@ import RIO.FilePath (takeBaseName, takeDirectory, (</>))
import RIO.List.Partial (foldr1)
contentRoute :: Routes
contentRoute = foldr1 composeRoutes [ directorizeRoute
, gsubRoute "posts/" (const "")
, gsubRoute "pages/" (const "")
, gsubRoute "projects/" (const "")
, stripDate
]
contentRoute = composeRoutes' [ directorizeRoute
, gsubRoute "posts/" (const "")
, gsubRoute "pages/" (const "")
, gsubRoute "projects/" (const "")
, stripDate
]
stripDate :: Routes
stripDate = gsubRoute "^[0-9]{4}-[0-9]{2}-[0-9]{2}-" (const "")
......@@ -29,3 +29,6 @@ directorizeRoute = customRoute createIndexRoute
dirPart = if basename == "index"
then directory
else directory </> basename
composeRoutes' :: [Routes] -> Routes
composeRoutes' = foldr1 composeRoutes
......@@ -3,10 +3,14 @@
// Parts taken from:
// https://blog.crashtest-security.com/lambda-edge-to-configure-http-security-headers-for-cloudfront-34a44775061d
exports.handler = async (event, ctx) => {
// https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html#lambda-event-structure-response
const request = event.Records[0].cf.request;
const response = event.Records[0].cf.response;
const headers = response.headers;
const securityHeaders = [
// the headers have to be in this weird list of object format for CloudFront
// https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-examples.html
const headersToAdd = [
[{
'key': 'Strict-Transport-Security',
'value': 'max-age=31536000'
......@@ -29,8 +33,16 @@ exports.handler = async (event, ctx) => {
}]
];
// Add all headers of the array to the response object in the correct format
for(let header of securityHeaders) {
// this file needs to readable by whatever random client I want to connect with
if (request.uri === '/.well-known/matrix/client') {
headersToAdd.push([{
'key': 'Access-Control-Allow-Origin',
'value': '*'
}])
}
// add all headers of the array to the response object in the correct format
for (let header of headersToAdd) {
headers[header[0].key.toLowerCase()] = header;
}
......
......@@ -117,6 +117,13 @@ sync-fix-mime:
--include="*.json" \
--mime-type="application/json"
s3cmd modify s3://$(AWS_S3_BUCKET) \
--verbose \
--recursive \
--exclude="*" \
--include=".well-known/matrix/*" \
--mime-type="application/json"
# TODO: getting easier to just exclude img path rather than specify all the others?
# would probably prefer `realpath --relative-to=$(DEST_DIR) {} \+`, but that's not happy inside docker
ASSETS = $(shell find $(DEST_DIR) -type f \( -path '*/css/*' -o -path '*/font/*' -o -path '*/js/*' -o -path '*/search/*.json' \) -exec sh -c "echo {} | sed -r 's|$(DEST_DIR)/?||'" \;)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment