Wednesday, February 24, 2016

node.js public folder static

server.js

var http = require('http');
var express = require("express");
var app = express();
var controllers = require("./controllers");

app.set("view engine", "vash");

// set the public static resource folder
app.use(express.static(__dirname + "/public"));

//map the routes
controllers.init(app);

app.get("/api/users", function (req, res) {
    res.set("Content-Type", "application/json");
    res.send({ name: "Greg", isValid: true, group: "Admin" });
});

var port = process.env.port || 3000;
var server = http.createServer(app);
server.listen(port);

layout.vash

<!DOCTYPE html>
<html>
<head>
<title>@model.title</title>
<link href="/css/site.css" rel="stylesheet" />
</head>
<body>
    <div> @html.block('body') </div>
</body>
</html>

No comments:

Post a Comment