Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var http = require('http');
- var app = require('./app');
- var express = require('express');
- var apps = express();
- var path = require('path');
- apps.use(express.static(path.join(__dirname, 'public')));
- http.createServer(app.handleRequest).listen(8000);
- var url = require('url');
- var fs = require('fs');
- function renderHTML(path, response) {
- response.writeHead(200, { 'Content-Type': 'text/html' });
- fs.readFile(path, null, function(error, data) {
- if (error) {
- response.writeHead(404);
- response.write('File not found!');
- } else {
- response.write(data);
- }
- response.end();
- });
- }
- module.exports = {
- handleRequest: function(request, response) {
- var path = url.parse(request.url).pathname;
- switch (path) {
- case '/':
- renderHTML('./index.html', response);
- break;
- case '/login':
- renderHTML('./login.html', response);
- break;
- default:
- response.writeHead(404);
- response.write('Route not defined');
- response.end();
- }
- }
- };
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Test Doc</title>
- <link rel="stylesheet" type="text/css" href="/css/style.css" />
- </head>
- <body>
- <p>Coba ku </p>
- <div id="container" style="height: 500px"></div>
- </body>
- </html>
Add Comment
Please, Sign In to add comment