'use strict'
var http = require('http');
var mappings = {
g: 'http://www.google.com'
};
var server = http.createServer(function(req, res) {
var alias = req.url.substring(1);
if (!mappings[alias]) {
res.writeHead(404);
res.end();
return;
}
res.writeHead(302, {
location: mappings[alias]
})
res.end();
});
server.listen(3000);
Forked from leommoore/node_create_a_redirect_server.md
Last active
July 19, 2025 17:28
-
-
Save balazsbohonyi/bbd35bf0b696fbc92715932de44b6e63 to your computer and use it in GitHub Desktop.
Create a redirect server in Node.js
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment