Wednesday, 12 April 2017

Express Only loads main page

I'm trying to learn express. I'm using FS to load my HTML Page. The only thing I could find on this with a google search was using ASP.NET instead of Express.

Server.js:

var express = require('express');
var path = require('path');
var fs = require('fs');

var app = express();

app.use(require('body-parser').urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname+'/')))

app.get('/', function(a,b,c){
  fs.readFileSync('index.html');
});

app.post('/testaction', function(a,b){
    console.log(a.body.log);
    fs.readFileSync('Logged.html');
});

app.listen(3000);

index.html:

<!DOCTYPE html>
<html>
  <head>
    <title>Test Page</title>
  </head>
  <body>
    <form method="post" action="http://localhost:3000/testaction">
      <h1>Log This:</h1>
      <input type="text" name="log"/>
      <input type="submit", value="Press Me!"/>
    </form>
  </body>
</html>



via AquaPlayzX

No comments:

Post a Comment