Serve frontend files from server using express

pull/54/merge
Candid Dauth 2016-10-18 14:27:20 +03:00
rodzic 0971e10de6
commit d56650c549
5 zmienionych plików z 33 dodań i 9 usunięć

Wyświetl plik

@ -34,6 +34,9 @@
"osmtogeojson": "^2.2.12",
"leaflet-fullHash": "https://raw.githubusercontent.com/KoGor/leaflet-fullHash/master/leaflet-fullHash.js"
},
"resolutions": {
"leaflet": "^1.0.1"
},
"overrides": {
"bootstrap": {
"main": [

Wyświetl plik

@ -17,6 +17,7 @@ var combine = require("stream-combiner");
var sourcemaps = require("gulp-sourcemaps");
var inject = require("gulp-inject");
var img64 = require("./gulpfile-img64");
var path = require("path");
var files = [
"app/**/*.js",
@ -36,7 +37,7 @@ gulp.task("clean", function() {
gulp.task("deps", function() {
return combine(
gulp.src(mainBowerFiles({ paths: { bowerDirectory: '../bower_components', bowerJson: '../bower.json' } }), { base: process.cwd() + "/" }),
gulp.src(mainBowerFiles({ paths: { bowerDirectory: __dirname + '/../bower_components', bowerJson: __dirname + '/../bower.json' } }), { base: path.resolve(__dirname + "/..") + "/" }),
gulpIf([ "**/*.js", "**/*.css" ], combine(
gulpIf("**/*.js", combine(
newer("build/dependencies.js"),
@ -105,7 +106,8 @@ gulp.task("all", [ "deps", "app" ], function() {
sourcemaps.init({ loadMaps: true }),
concat("all.css"),
sourcemaps.write("./sourcemaps")
)
),
gulp.src("deref.html")
),
gulp.dest("build")
);
@ -115,8 +117,9 @@ gulp.task("index", [ "all" ], function() {
return combine(
gulp.src("index.html"),
img64(),
concat("build/index.html"),
inject(gulp.src([ "build/all.js", "build/all.css" ], { read: false }), { relative: true, removeTags: true }),
gulp.dest("build")
gulp.dest(".")
);
});

Wyświetl plik

@ -36,6 +36,6 @@
<!-- inject:js -->
<!-- endinject -->
<script src="http://localhost:40829/socket.io/socket.io.js"></script>
<script src="socket.io/socket.io.js"></script>
</body>
</html>

Wyświetl plik

@ -4,11 +4,16 @@
"author": "Candid Dauth <cdauth@cdauth.eu>",
"version": "0.0.1",
"scripts": {
"start": "node server/server.js"
"start": "npm run deps && npm run build && npm run server",
"deps": "npm update --dev && bower update",
"build": "gulp",
"server": "node server/server.js",
"clean": "gulp clean"
},
"dependencies": {
"cheerio": "^0.22.0",
"compressjs": "^1.0.3",
"express": "^4.14.0",
"promise": "^7.1.1",
"request": "^2.75.0",
"request-promise": "^4.1.1",

Wyświetl plik

@ -9,6 +9,10 @@ var routing = require("./routing");
var gpx = require("./gpx");
var search = require("./search");
var Promise = require("promise");
var express = require("express");
var path = require("path");
var frontendPath = path.resolve(__dirname + "/../frontend");
Object.defineProperty(Error.prototype, "toJSON", {
value: function() {
@ -25,9 +29,18 @@ Object.defineProperty(Error.prototype, "toJSON", {
var dbP = database.connect();
var app = http.createServer();
var appP = Promise.denodeify(app.listen.bind(app))(config.port, config.host).then(function() {
var io = socketIo.listen(app);
var app = express();
app.use(express.static(frontendPath + "/build/"));
app.get("/:padId", function(req, res) {
res.sendFile(frontendPath + "/build/index.html");
});
var server = http.createServer(app);
var serverP = Promise.denodeify(server.listen.bind(server))(config.port, config.host).then(function() {
var io = socketIo.listen(server);
io.sockets.on("connection", function(socket) {
var d = domain.create();
@ -309,7 +322,7 @@ var appP = Promise.denodeify(app.listen.bind(app))(config.port, config.host).the
});
});
Promise.all([ dbP, appP ]).then(function() {
Promise.all([ dbP, serverP ]).then(function() {
console.log("Server started on " + (config.host || "*" ) + ":" + config.port);
}).catch(function(err) {
console.error(err);