Created
September 12, 2018 23:40
-
-
Save Nash0x7E2/f2ff5e0cbebb4df586781390ce0a988c to your computer and use it in GitHub Desktop.
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
import 'dart:async'; | |
import 'dart:io'; | |
void main() { | |
TestHttpServer().createHttpServer(); | |
} | |
class TestHttpServer { | |
HttpServer server; | |
Future<void> createHttpServer() async { | |
server = await HttpServer.bind( | |
InternetAddress.loopbackIPv4, | |
3000, | |
); | |
print('Listening on localhost:${server.port}'); | |
await for (HttpRequest request in server) { | |
request.response.headers.add('Content-Type', 'text/html'); | |
//sets up the default route | |
if (request.uri.path == "/") { | |
request.response | |
..write(''' | |
<center> | |
<h1>Home sweet home</h1> | |
</center> | |
''') | |
..close(); | |
} | |
if (request.uri.path == "/nash") { | |
request.response | |
..write(''' | |
<center> | |
<h1>Someone actually cares</h1> | |
</center> | |
''') | |
..close(); | |
print("Some one is looking me up?"); | |
} | |
if (request.uri.path == "/john") { | |
request.response | |
..write(''' | |
<center> | |
<h1 style="color:red;"> Why hello John.... </h1> | |
</center> | |
''') | |
..close(); | |
print("This is what I was rambling on about"); | |
} | |
if (request.uri.path == "/secret") { | |
request.response | |
..write(''' | |
<center> | |
<h1 style="color:red;"> This is a top secret route.... </h1> | |
</center> | |
''') | |
..close(); | |
print("Someone is accessing top secret"); | |
} | |
} | |
} | |
void killServer() { | |
server.close(force: true); | |
print('Server is now dead'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment