12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- const express = require('express');
- const path = require('path');
- const app = express();
- app.use(express.static('public'));
- app.get('/', (request, response) => {
- console.log(path.resolve(__dirname, 'index.html'));
- console.log(__dirname);
- response.sendFile(path.resolve(__dirname, 'index.html'));
- });
- app.get('/about', (request, response) => {
- response.sendFile(path.resolve(__dirname, 'about.html'));
- });
- app.get('/contato', (req, res) => {
- res.sendFile(path.resolve(__dirname, 'contato.html'));
- });
- app.listen(3000, () => {
- console.log('App listening on port 3000');
- });
- // const http = require('http')
- // const fs = require('fs')
- // ReadFile tem colocar a função depois que readFile é concluido, funão assincrona
- // const aboutPage = fs.readFile('about.html', (file) => {})
- // const aboutPage = fs.readFileSync('about.html');
- // const contatoPage = fs.readFileSync('contato.html');
- // const homePage = fs.readFileSync('index.html');
- // const server = http.createServer((request, response) => {
- // console.log(request.url);
- // if (request.url === '/about') {
- // return response.end(aboutPage);
- // } else if (request.url === '/contato') {
- // return response.end(contatoPage);
- // } else if (request.url === '/') {
- // return response.end(homePage);
- // } else {
- // response.writeHead(404);
- // response.end('The page not found');
- // }
- // });
- // server.listen(3000);
|