Skip to content

Instantly share code, notes, and snippets.

@FiveYellowMice
Last active March 25, 2016 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FiveYellowMice/90e8eba1192242399d37 to your computer and use it in GitHub Desktop.
Save FiveYellowMice/90e8eba1192242399d37 to your computer and use it in GitHub Desktop.
Backend of https://fivy.ml
#!/usr/bin/env lua
local website = "https://fiveyellowmice.com"
local mapping = {
home = "/",
about = "/about/",
projects = "/projects/",
newstyle = "/newstyle/",
search = "/search/",
posts = "/posts/",
rss = "/feed.xml",
}
local url = os.getenv("REQUEST_URI"):sub(12, (os.getenv("REQUEST_URI"):find("?") or 101) - 1)
if url == "" then
local table = "";
for i in pairs(mapping) do
table = table .. "<tr><td><a href=\""..website..mapping[i].."\">"..i.."</a></td><td>"..mapping[i].."</td></tr>"
end
print([[
Content-Type: text/html; charset=utf-8
<html>
<head>
<meta charset="utf-8" />
<meta name="robots" content="noindex" />
<title>FiveYellowMice's Short URL</title>
</head>
<body>
<h1>FiveYellowMice's Short URL</h1>
<p>这里的短链接是为 <a href="]] .. website .. [[">FiveYellowMice's Blog</a> 准备的。如果你需要生成短链接,可别找我。</p>
<table>]] .. table .. [[</table>
</body>
</html>]])
elseif mapping[url] then
print([[
Status: 301 Moved Permanently
Content-Type: text/html; charset=utf-8
Location: ]] .. website .. mapping[url] .. [[
<html><head></head><body><p>Redirecting to <a href="]] .. website .. mapping[url] .. [[">here</a>.</p></body></html>]])
else
print([[
Status: 404 Not Found
Content-Type: text/html; charset=utf-8
<p>Not found.</p>]])
end
@einverne
Copy link

在后台用的什么 Web Server 呢? Nginx吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment