A minimalistic web server that converts pages written in Markdown to HTML. It
will serve any Markdown located in the pages
directory as HTML using the
file's path as its access point. Files named index.md
are considered base
routes. For instance:
- The file
pages/index.md
is accessible at/
- The file
pages/blog/ireland.md
is accessible at/blog/ireland
- The file
pages/blog/index.md
is accessible at/blog
The site's layout is defined by the HTML in public/index.html
. Opening that
file, you'll notice the token %APP%
which is where a page's converted HTML
gets injected.
MDServe does not enable client-side Javascript by default. If your application requires it, you have a couple options:
- If plain Javascript is all you need, add it to the
public
directory and add referenced<script>
tag(s) topublic/index.html
. - If you prefer Typescript, files in the
src/js/
directory are served by a special/js*
handler. Openpublic/index.html
and uncomment the script tag referencing/js/main.js
. Thisjs/main.js
file is emitted by the Typescript compiler fromsrc/js/main.ts
. You may add additional Typescript tosrc/js/
but, since it is executed in the browser, it needs to be bundled in order to userequire
/import
statements.
pages/
- Stores Markdown pages and defines the site's routingpublic/
- Static assetssrc/
- The ExpressJS server
- NodeJS v18 or higher
- Optional: Docker
- Clone this repository
git clone https://github.com/dan-lovelace/md-serve.git
- Change into the new directory
cd md-serve
- Start the server using one of the following options: from source or with Docker
- Install dependencies
npm install
- Start the development server
npm run dev
- Build and run the container using default configuration
docker compose up --build
- Build and run using a specific environment file
docker compose --env-file=".env.development" up --build
The npm run dev
command starts the server from source and watches for changes
to the pages
, public
and src
directories. The base HTML inherited by all
pages can be found in public/index.html
and anything in the public
directory
is served statically.
There is a src/js
directory that is used to store any necessary Javascript for
the browser. There is no bundling solution shipped by default but one could be
added depending on needs.
- Create a new repository in ECR
aws ecr create-repository md-serve
- Login to the new repository with Docker - Replace
ACCOUNT_NUMBER
andREGION
with your ownaws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin ACCOUNT_NUMBER.dkr.ecr.REGION.amazonaws.com/md-serve
- Build the latest image
docker compose build
- Note: You may provide an environment file using the
--env-file
flag like this:docker compose --env-file=".env.production" build
- Note: You may provide an environment file using the
- Create a tag pointing to the ECR repository - Replace
ACCOUNT_NUMBER
andREGION
with your owndocker tag md-web-server:latest ACCOUNT_NUMBER.dkr.ecr.REGION.amazonaws.com/md-serve
- Push the image to the remote repository
docker push ACCOUNT_NUMBER.dkr.ecr.REGION.amazonaws.com/md-serve
Below are some very loose steps for AWS deployment options and there is an endless list of other options for hosting Docker containers.
- Create a new EC2 instance using an image that has Linux and Docker - Look in the AWS marketplace
- Create an elastic IP and associate it with the instance
- SSH into the machine and run that
aws ecr get-login-password ... | docker login ...
command from above to login to docker - Runaws configure
to set up credentials or edit~/.aws/config
and~/.aws/credentials
manually - Pull the image
docker pull ACCOUNT_NUMBER.dkr.ecr.REGION.amazonaws.com/md-serve-repo:latest
- Get the image id with
docker images
- Run it using the image id and expose the correct port(s)
docker run -d -p 8000:8000 2ce25025a251
- Navigate to the instance's public IP
- Homepage should display
- Create a new ECS cluster
- Create a new ECS Task Definition using the ECR image
- Create a new ECS Service that uses the new Task Definition
- Wait for task to start and select it
- Navigate to the task's public IP
- Homepage should display
https://repost.aws/knowledge-center/ecs-fargate-static-elastic-ip-address