Skip to content

Instantly share code, notes, and snippets.

@aldebaran798
Last active June 15, 2017 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aldebaran798/c1762a669d3719d70b37c7ea726d1ca7 to your computer and use it in GitHub Desktop.
Save aldebaran798/c1762a669d3719d70b37c7ea726d1ca7 to your computer and use it in GitHub Desktop.
FrontExpress Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://cdn.jsdelivr.net/frontexpress/1.0.1/frontexpress.min.js"></script>
<title>Prueba Front Express</title>
</head>
<body>
Probando <br />
<a href="page1"> page 1</a>
<a href="page2"> page 2</a>
<a href="page3"> page 3</a>
<div class="content"></div>
<script>
// Front-end application
const app = frontexpress();
// front-end logic on navigation path "Root"
app.get('/', (req, res) => {
document.querySelector('.content').innerHTML = `<h1>Index</h1>`;
});
// front-end logic on navigation path "/page1"
app.get('/page1', (req, res) => {
document.querySelector('.content').innerHTML = `<h1>Page 1 content</h1>`;
});
// front-end logic on navigation path "/page2"
app.get('/page2', (req, res) => {
document.querySelector('.content').innerHTML = `<h1>Page 2 content</h1>`;
});
// start front-end application
app.listen(() => {
// on DOM ready
console.log('App is listening requests');
});
</script>
</body>
</html>
const
express = require('express'),
app = express(),
path = require('path');
app.use(express.static('public'));
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname + '/index.html'));
})
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})
{
"name": "prueba_frontexpress",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment