Last active
October 23, 2023 15:28
-
-
Save renatoathaydes/8ad276cedd515f8ff5fc to your computer and use it in GitHub Desktop.
A simple web server written in Groovy that provides static and code-generated content
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
#!/usr/bin/env groovy | |
import org.eclipse.jetty.server.Server | |
import org.eclipse.jetty.servlet.* | |
import groovy.servlet.* | |
@Grab(group='org.eclipse.jetty.aggregate', module='jetty-all', version='7.6.15.v20140411') | |
def startJetty() { | |
def server = new Server(8080) | |
def handler = new ServletContextHandler(ServletContextHandler.SESSIONS) | |
handler.contextPath = '/' | |
handler.resourceBase = '.' | |
handler.welcomeFiles = ['index.html'] | |
handler.addServlet(GroovyServlet, '/scripts/*') | |
def filesHolder = handler.addServlet(DefaultServlet, '/') | |
filesHolder.setInitParameter('resourceBase', './public') | |
server.handler = handler | |
server.start() | |
} | |
println "Starting Jetty, press Ctrl+C to stop." | |
startJetty() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Even shorter with no dependencies: