Skip to content

Instantly share code, notes, and snippets.

@zewa666
Created December 28, 2016 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zewa666/ca1d5b0cf1fdccd5f756948fa64c66dd to your computer and use it in GitHub Desktop.
Save zewa666/ca1d5b0cf1fdccd5f756948fa64c66dd to your computer and use it in GitHub Desktop.
Running Aurelia-CLI with Node ExpressJS
'use strict';
// simple express server
var express = require('express');
var path = require('path');
var app = express();
var router = express.Router();
app.use("/scripts", express.static(path.join(__dirname, 'scripts')));
app.get('/', function(req, res) {
res.sendfile('./index.html');
});
app.listen(9000);
import gulp from 'gulp';
import browserSync from 'browser-sync'
import historyApiFallback from 'connect-history-api-fallback/lib';;
import project from '../aurelia.json';
import build from './build';
import {CLIOptions} from 'aurelia-cli';
import * as nodemon from 'gulp-nodemon';
function onChange(path) {
console.log(`File Changed: ${path}`);
}
function reload(done) {
browserSync.reload();
done();
}
function runNode(cb) {
let started = false;
return nodemon.default({
script: 'app.js'
}).on('start', function () {
if (!started) {
cb();
started = true;
}
});
}
let serve = gulp.series(
build,
runNode,
done => {
browserSync({
online: false,
open: false,
port: 7000,
proxy: "http://localhost:9000",
logLevel: 'silent',
server: {
baseDir: ['.'],
middleware: [historyApiFallback(), function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
next();
}]
}
}, function (err, bs) {
let urls = bs.options.get('urls').toJS();
console.log(`Application Available At: ${urls.local}`);
console.log(`BrowserSync Available At: ${urls.ui}`);
done();
});
}
);
let refresh = gulp.series(
build,
reload
);
let watch = function() {
gulp.watch(project.transpiler.source, refresh).on('change', onChange);
gulp.watch(project.markupProcessor.source, refresh).on('change', onChange);
gulp.watch(project.cssProcessor.source, refresh).on('change', onChange)
}
let run;
if (CLIOptions.hasFlag('watch')) {
run = gulp.series(
serve,
watch
);
} else {
run = serve;
}
export default run;
npm install --save express
npm install --save-dev nodemon
@ajile-in
Copy link

Cool, I was exactly trying the same approach with 'proxy' option, except I wasn't able to figure out the "runNode" task.
Thanks Vildan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment