search

Home  >  Q&A  >  body text

angular.js - How to deploy angular static web pages to node

I have a static angular project that can run on Apache, and I want to migrate it to the node environment. I don’t know how to write node’s server.js and page.json.

大家讲道理大家讲道理2871 days ago609

reply all(5)I'll reply

  • 阿神

    阿神2017-05-15 16:57:19

    Just write it like this in KOA

    var koa = require('koa');
    var serve = require('koa-static');
    var path = require('path');
    
    // KOA框架
    var app = module.exports = koa();
    
    // 错误处理
    app.on('error', function(err, ctx){
        console.log(err.message);
    });
    
    // 静态中间件
    app.use(serve(path.join(__dirname, 'public')));
    
    // 监听端口
    if (!module.parent){
        app.listen(3000);
        logger.info('My Website run on 3000...');
    }

    /app.js
    /public/index.html //angular entrance

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-15 16:57:19

    Use nokit, one line of command:

    $ cd <angular项目目录>
    $ nokit start <port> -public:./

    For more detailed usage, check http://nokit.org

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-15 16:57:19

    Put it directly in the static file. After use, just access the static page address directly. This is how this game works
    http://tianmaying.com/app/collect-b/index.html

    reply
    0
  • 为情所困

    为情所困2017-05-15 16:57:19

    express

    reply
    0
  • 为情所困

    为情所困2017-05-15 16:57:19

    Hey, try sero-cli. The second item is "Start a static web server for current working directory". Use this command in the root directory of your angular project. Just select the second item.

    reply
    0
  • Cancelreply