Code Monkey home page Code Monkey logo

wing's Introduction

Wing is a modern web services platform written in Perl. It allows you to define objects and then automatically generates database schemas, restful web services, and even web form handlers to manage those objects. It's got built in users, sessions, single-sign-on and more.


INSTALLATION

0. Do the prep for your OS. For example, if you're on Amazon Linux, then look at README.Amazon.txt to see the prep steps.

1. Clone this repository into /data/Wing on your machine:

  mkdir /data
  cd /data
  git clone https://github.com/plainblack/Wing.git

2. Install the prereqs.

  /data/Wing/bin/setup/setup.sh

3. Verify/set apps paths.

  perl -v  # should return 5.26.2, the version required by Wing.  If not:
  source /data/Wing/bin/dataapps.sh
  perl -v  # should return 5.26.2

4. Create a project in /data/MyApp:

  cd /data/Wing/bin
  export WING_HOME=/data/Wing
  perl wing_init_app.pl --app=MyApp

  NOTE: If you get an error a la "Illegal division by zero" from warnings.pm in this step, revisit step 3.

5. Create a database on your MySQL server to host the project, and edit the Wing config to match:

  NOTE: It is important that your my.cnf file for MySQL contain the following lines in the [mysqld] section. If not, add them and restart it:

    collation_server=utf8_unicode_ci
    character_set_server=utf8

  mysql -uroot -p -e "create database my_project"
  mysql -uroot -p -e "grant all privileges on my_project.* to some_user@localhost identified by 'some_pass'" 
  mysql -uroot -p -e "flush privileges" 

6. Modify the config file. You need to at least edit the "db" section to tell Wing how to log in to your database. You may also wish to update other settings.

  vi /data/MyApp/etc/wing.conf  
  mkdir /data/apps/logs
  chown nobody /data/apps/logs

  NOTE: You can also edit the location of the logs in /data/MyApp/etc/log4perl.conf. It is defaultly set to /data/apps/logs/wing.log

7. Initialize the database:

  cd /data/MyApp/bin
  export WING_HOME=/data/Wing
  export WING_APP=/data/MyApp/
  export WING_CONFIG=/data/MyApp/etc/wing.conf

  wing db --prepare_install
  wing db --install --force

8. Start up the rest server and/or web server:

  wing rest --start
  wing web --start

9. Now you can connect to the rest server and see if it's alive:

  curl http://localhost:5000/api/status

  curl http://localhost:5001/account

  NOTE: By default there is one user named 'Admin' with a password of '123qwe'.

10. We also provide you with an nginx config file to give you a baseline for serving your apps. You can start it like this:

  nginx -c /data/MyApp/etc/nginx.conf

  NOTE: This is required to merge together the two services, as well as serve up static files.

  WARNING: There is no "home" page. Wing is expecting you to create it. After you start Nginx you'll be able to access /account and /admin. Everything is will 404. 


OPTIONAL

11. Wing has a job server called Wingman, which is backed by beanstalkd. To run it you simply install beanstalkd, which you can download from here: http://kr.github.io/beanstalkd/

Then you can run it like so:

beanstalkd &

And finally you run Wing's job server by typing:

  wing wingman --start





ADDING FUNCTIONALITY

We also provide you with tools to build out your app. For example, if you want to add a new class to your app, you can:

  wing class --add=NewObject
 
This will dynamically generate a NewObject.pm class file for you in /data/MyApp/lib/MyApp/DB/Result/, and create a Rest
interface at /data/MyApp/lib/MyApp/Rest/NewObject.pm, and create a Web interface at /data/MyApp/lib/MyApp/Web/NewObject.pm.
It will even add the lines needed in /data/MyApp/lib/MyQpp/Rest.pm and /data/MyApp/lib/MyApp/Web.pm.

After adding a new class you'll need to restart a few services:

  cd /data/MyApp/bin
  ./restart_web.sh
  ./restart_rest.sh
  wingman.pl restart

To upgrade your database with the schema changes for your new class:

  increment the database version number in MyApp::DB
  wing db --prepare
  wing db --upgrade

For more information on managing the database schema see the DBIx::Class::DeploymentHandler documentation.

Once you've built out your object and you're ready to generate some web templates for it you can do:

  wing class --template=NewObject
 
That will add templates in /data/MyApp/views/newobject/*.tt. 

We can even generate some basic tests for you:

  wing class --test=NewObject

That will add tests in /data/MyApp/t


For more information type:

  perldoc lib/Wing/FirstApp.pod



wing's People

Contributors

amoore avatar daviddelikat avatar perldreamer avatar rizen avatar scottwalters avatar storian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wing's Issues

wing.js 404 error

I went through the install process, and can get the /login and /account pages to serve OK, but I cant get wing.js to work. I get a 404 error for it:

2013/06/08 14:54:13 INFO request: GET /wing.js from 127.0.0.1
2013/06/08 14:54:13 INFO Trying to match 'GET /wing.js' against /^/login$/ (generated from '/login')
2013/06/08 14:54:13 INFO Trying to match 'GET /wing.js' against /^/logout$/ (generated from '/logout')
2013/06/08 14:54:13 INFO Trying to match 'GET /wing.js' against /^/account/apikeys$/ (generated from '/account/apikeys')
2013/06/08 14:54:13 INFO Trying to match 'GET /wing.js' against /^/account/apikey/([^\/]+)$/ (generated from '/account/apikey/:id')
2013/06/08 14:54:13 INFO Trying to match 'GET /wing.js' against /^/account$/ (generated from '/account')
2013/06/08 14:54:13 INFO Trying to match 'GET /wing.js' against /^/account/reset-password$/ (generated from '/account/reset-password')
2013/06/08 14:54:13 INFO Trying to match 'GET /wing.js' against /^/account/reset-password-code$/ (generated from '/account/reset-password-code')
2013/06/08 14:54:13 INFO Trying to match 'GET /wing.js' against /^/sso$/ (generated from '/sso')
2013/06/08 14:54:13 INFO Trying to match 'GET /wing.js' against /^/sso/authorize$/ (generated from '/sso/authorize')
2013/06/08 14:54:13 INFO Trying to match 'GET /wing.js' against /^/sso/success$/ (generated from '/sso/success')
2013/06/08 14:54:13 INFO Trying to match 'GET /wing.js' against /^/account/facebook$/ (generated from '/account/facebook')
2013/06/08 14:54:13 INFO Trying to match 'GET /wing.js' against /^/account/facebook/postback$/ (generated from '/account/facebook/postback')
2013/06/08 14:54:13 INFO Trying to match 'GET /wing.js' against /^/account/profile/([^\/]+)$/ (generated from '/account/profile/:id')
2013/06/08 14:54:13 INFO Trying to match 'GET /wing.js' against /^/admin/users$/ (generated from '/admin/users')
2013/06/08 14:54:13 INFO Trying to match 'GET /wing.js' against /^/admin/user/([^\/]+)$/ (generated from '/admin/user/:id')
2013/06/08 14:54:13 INFO Trying to match 'GET /wing.js' against /(?^:^(?^:.)$)/ (generated from '(?^:.)')
2013/06/08 14:54:13 INFO --> got 1
2013/06/08 14:54:13 ERROR request to GET /wing.js crashed: Page Not Found at /data/Wing/lib/Wing/Web/NotFound.pm line 9.

I can't figure out exactly how the routing or dispatch is supposed to serve this out of the /data/Wing directory. Can you give me a pointer on how it's supposed to work, please? Maybe it's just my installation.

unable to install empty database

I think that the installation instructions in the README do not provide enough SQL to actually install the database. When I get to the "wing db --install" portion of the installation script, it fails with this error:

$ /data/apps/bin/perl $WING_HOME/bin/wing db --install --force
For /data/TheBook/etc/wing.conf...
Current code version 1...
No version control installed in this database.
Installing a new database with version 1
/data/TheBook/dbicdh/MySQL does not exist; please write/generate some SQL at /data/apps/lib/perl5/site_perl/5.16.2/darwin-2level/Moose/Meta/Method/Delegation.pm line 110.
DBIx::Class::Storage::TxnScopeGuard::DESTROY(): A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or error. Rolling back. at /data/apps/lib/perl5//5.16.2/Carp.pm line 100

Perhaps I have to "wing_add_class.pl" first, but I'd think that the Users table should at least get installed at this point.

Notes on FirstApp

For things that you always want importing, you might consider Import::Into / Import::Base to bundle them together to avoid the boilerplate.

Might also be nice to use exported subroutines instead of class method calls for the DBIC stuff plus DBIx::Class::Candy for declaring DBIC specific bits.

search()->single is vomit worthy, instead declare a unique constraint in your result class, which will make DBIC deploy the right thing, and you'll be able to use find().

also it seems strange to me not to have the uri_part by default but using 'id' by default, and then you could auto-generate routes that already have the correct redirect (plus I'd abstract out the redirect generation a bit but I guess that's a taste thing)

password reset codes

Password reset codes are very long, but that's hard on folks using phones if they don't know how to copy/paste. We should change them to 6 random characters.

unable to serialize DateTimes

When using Wing::Role::Result::DateTimeField, I get a "500" error when trying to view objects that contain DateTime fields. It's like this:

2013/06/19 20:09:54 DEBUG {
"result" : {
"error" : {
"data" : null,
"code" : 500,
"message" : "Serializer (Dancer::Serializer::JSON) failed at serializing HASH(0x7fbc8b9b6470):\nencountered object '2013-06-20T12:24:45', but neither allow_blessed nor convert_blessed settings are enabled at (eval 124) line 151.\n"
}
}
}

I think this is because the JSON serializer isn't configured to serialized blessed objects. If I update config.yml to include:
engines:
JSON:
allow_blessed: 1
convert_blessed: 1

then it works. Is this the correct fix for this problem? I'll drop you a patch if it seems like this is the right way to go.

Thanks,
-Andy

Logging categories

Wing uses the root logger inside Log4perl, which means that there's no way to set individual logging levels or configs for it versus Dancer, or even inside different Wing components (like web.psgi, rest.psgi, wingman, TGC's stitcher, etc.)

Wing.pm should use $ENV{WING_LOGGER_IDENTITY} || $0 to make it easy to use Log4perl's categories for sectioning levels and other logging issues.

Wingman not requesting more time correctly

If you have a job that needs to run longer you should be able to call ->touch and on the job and then the job won't be handed out to another worker. However, I've seen 2 instances where the time ran out despite calling ->touch and then another worker spun up running the same job.

Wingman.pm

The JSON decoder in Wingman.pm assumes that the decode will be successful, which is of course silly.

So we just need to modify this line:

$beanstalk->decoder(sub { @{decode_json(shift)} });

to be more intelligent

Chat: Simultaneous posts

If two people submit a post at the same time, then "your" post doesn't show up in your chat until you refresh the screen.

Warning in DBI::mysql on first app

Use of uninitialized value $mysql_ver in numeric lt (<) at /data/apps/lib/perl5/site_perl/5.16.2/DBIx/Class/Storage/DBI/mysql.pm line 117.

504 bug on empty array in field options

__PACKAGE__->wing_fields(
some_field => {
  dbic => ..
 ...
  options => sub { return [] },
},
);

Passing a sub ref to options, which then ultimately returns an empty array causes a 504 error. It's bad for it to return an empty array anyway. It should never be done. But even so, it should not be a 504 error.

add a Permanently Deactivate Account feature

add it to Wing::Role::DB::Result::User

When an account is disabled it should do the following:

a) be the same as setting the no emails ever flag, not actually setting it, just overriding it. BTW, I'm not sure if this is a feature of wing or of the individual apps. if it's in the individual apps please move it to wing.

b) do not allow logins

c) do not allow password recovery, instead say this account has been permanently deactivated

d) show as disabled in the admin user search

e) make it so the user can hit a button to disable their own account. When they do this it should:

e1) Ask them to type their password to confirm with the message: Type your password to PERMANENTLY DEACTIVATE YOUR ACCOUNT.

e2) Log them out.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.