Skip to content

Instantly share code, notes, and snippets.

@Nash0x7E2
Created September 12, 2018 23:40
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 Nash0x7E2/f2ff5e0cbebb4df586781390ce0a988c to your computer and use it in GitHub Desktop.
Save Nash0x7E2/f2ff5e0cbebb4df586781390ce0a988c to your computer and use it in GitHub Desktop.
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