Last active
March 25, 2016 09:04
-
-
Save FiveYellowMice/90e8eba1192242399d37 to your computer and use it in GitHub Desktop.
Backend of https://fivy.ml
This file contains hidden or 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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
在后台用的什么 Web Server 呢? Nginx吗?